11import z from 'zod'
22
33import { type ApiRouteHandler , type ApiRouteSchema , createEndpoint } from '../../endpoint'
4+ import type { AuthConfig } from '..'
45import { AccountProvider } from '../constant'
56import { type AuthContext } from '../context'
6- import { setSessionCookie } from '../utils'
7+ import { hashPassword , setSessionCookie } from '../utils'
78
8- interface InternalRouteOptions {
9- autoLogin ?: boolean
10- }
11-
12- export function signUp < const TOptions extends InternalRouteOptions > ( options : TOptions ) {
9+ export function signUp < const TOptions extends AuthConfig > ( options : TOptions ) {
1310 const schema = {
1411 method : 'POST' ,
1512 path : '/api/auth/sign-up' ,
@@ -34,7 +31,9 @@ export function signUp<const TOptions extends InternalRouteOptions>(options: TOp
3431 } as const satisfies ApiRouteSchema
3532
3633 const handler : ApiRouteHandler < AuthContext , typeof schema > = async ( args ) => {
37- const hasedPassword = args . body . password // TODO: hash password
34+ const hasedPassword =
35+ ( await options . emailAndPassword ?. passwordHasher ?.( args . body . password ) ) ??
36+ ( await hashPassword ( args . body . password ) )
3837
3938 const user = await args . context . internalHandlers . user . create ( {
4039 name : args . body . name ,
@@ -60,7 +59,7 @@ export function signUp<const TOptions extends InternalRouteOptions>(options: TOp
6059 } )
6160
6261 const responseHeaders = { }
63- if ( options . autoLogin ) {
62+ if ( options . emailAndPassword ?. signUp ?. autoLogin !== false ) {
6463 // Set session cookie if auto login is enabled
6564 setSessionCookie ( responseHeaders , session . token )
6665 }
0 commit comments