11import z from 'zod'
22
3- import { ApiRoute , ApiRouteHandler , ApiRouteSchema } from '~/core/endpoint'
4-
3+ import { ApiRouteHandler , ApiRouteSchema , createEndpoint } from '../../endpoint'
54import { AccountProvider } from '../constant'
65import { AuthContext } from '../context'
76import { WithPrefix } from '../types'
@@ -14,23 +13,22 @@ interface InternalRouteOptions {
1413export function signInEmail < const TOptions extends InternalRouteOptions > ( options : TOptions ) {
1514 const schema = {
1615 method : 'POST' ,
17- path : ( options . prefix ? `${ options . prefix } /sign-in/email` : '/sign-in/email' ) as WithPrefix <
18- TOptions [ 'prefix' ] ,
19- '/sign-in/email'
20- > ,
16+ path : ( options . prefix
17+ ? `${ options . prefix } /auth/sign-in/email`
18+ : '/auth/sign-in/email' ) as WithPrefix < TOptions [ 'prefix' ] , '/auth/sign-in/email' > ,
2119
22- body : z . interface ( {
20+ body : z . object ( {
2321 email : z . string ( ) ,
2422 password : z . string ( ) ,
2523 } ) ,
2624 responses : {
27- 200 : z . interface ( {
25+ 200 : z . object ( {
2826 token : z . string ( ) . nullable ( ) ,
29- user : z . interface ( {
27+ user : z . object ( {
3028 id : z . string ( ) ,
3129 name : z . string ( ) ,
3230 email : z . string ( ) ,
33- ' image?' : z . string ( ) . nullable ( ) ,
31+ image : z . string ( ) . nullable ( ) . optional ( ) ,
3432 } ) ,
3533 } ) ,
3634 } ,
@@ -54,7 +52,7 @@ export function signInEmail<const TOptions extends InternalRouteOptions>(options
5452 expiresAt : new Date ( Date . now ( ) + 1000 * 60 * 60 * 24 ) ,
5553 } )
5654
57- const responseHeaders = new Headers ( )
55+ const responseHeaders = { }
5856 setSessionCookie ( responseHeaders , session . token )
5957
6058 return {
@@ -67,8 +65,5 @@ export function signInEmail<const TOptions extends InternalRouteOptions>(options
6765 }
6866 }
6967
70- return {
71- ...schema ,
72- handler,
73- } satisfies ApiRoute
68+ return createEndpoint ( schema , handler )
7469}
0 commit comments