File tree Expand file tree Collapse file tree 2 files changed +7
-10
lines changed
storage/framework/core/auth/src Expand file tree Collapse file tree 2 files changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -104,11 +104,13 @@ export class Auth {
104104 } )
105105 . executeTakeFirst ( )
106106
107- if ( ! result ?. insertId )
107+ const insertId = Number ( result ?. insertId ) || Number ( result ?. numInsertedOrUpdatedRows )
108+
109+ if ( ! insertId )
108110 throw new HttpError ( 500 , 'Failed to create token' )
109111
110112 // Encrypt the token ID using client secret
111- const encryptedId = encrypt ( result . insertId . toString ( ) , clientSecret )
113+ const encryptedId = encrypt ( insertId . toString ( ) , clientSecret )
112114
113115 // Combine into final token format with JWT first
114116 return `${ jwtToken } :${ encryptedId } ` as AuthToken
Original file line number Diff line number Diff line change 11import type { NewUser } from '@stacksjs/orm'
22import type { AuthToken } from './token'
33import { db } from '@stacksjs/database'
4+ import { User } from '@stacksjs/orm'
45import { makeHash } from '@stacksjs/security'
56import { Auth } from './authentication'
67
78export async function register ( credentials : NewUser ) : Promise < { token : AuthToken } | null > {
89 const { email, password, name } = credentials
910
1011 // Check if user already exists
11- const existingUser = await db . selectFrom ( 'users' )
12- . where ( 'email' , '=' , email )
13- . selectAll ( )
14- . executeTakeFirst ( )
12+ const existingUser = await User . where ( 'email' , '=' , email ) . first ( )
1513
1614 if ( existingUser )
1715 return null
@@ -34,10 +32,7 @@ export async function register(credentials: NewUser): Promise<{ token: AuthToken
3432 return null
3533
3634 // Get the created user
37- const user = await db . selectFrom ( 'users' )
38- . where ( 'id' , '=' , insertId )
39- . selectAll ( )
40- . executeTakeFirst ( )
35+ const user = await User . find ( insertId )
4136
4237 if ( ! user )
4338 return null
You can’t perform that action at this time.
0 commit comments