Skip to content

Commit 60e0a92

Browse files
authored
fix(auth): restore signup user response (#2391)
1 parent a7bdb23 commit 60e0a92

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

packages/core/auth-js/src/lib/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export function _sessionResponse(data: GoTrueSessionData): AuthResponse {
255255

256256
// Some /verify responses (e.g. secure email_change first-confirmation) return
257257
// only `{ msg, code }` with no user and no session. Treat those as null user.
258-
const user: User | null = data.user ?? null
258+
const user: User | null = data.user ?? (typeof data?.id === 'string' ? (data as User) : null)
259259
return { data: { session, user }, error: null }
260260
}
261261

packages/core/auth-js/test/GoTrueClient.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,38 @@ describe('GoTrueClient', () => {
567567
expect(data?.user?.user_metadata).toMatchObject(TEST_USER_DATA)
568568
})
569569

570+
test('signUp() returns the bare user payload when signup requires confirmation', async () => {
571+
const user = {
572+
id: 'user-id',
573+
aud: 'authenticated',
574+
role: 'authenticated',
575+
email: 'user@example.com',
576+
created_at: '2026-05-21T12:00:00.000Z',
577+
}
578+
const mockFetch = jest.fn().mockResolvedValue({
579+
ok: true,
580+
status: 200,
581+
headers: new Headers(),
582+
json: () => Promise.resolve(user),
583+
})
584+
const client = new GoTrueClient({
585+
url: GOTRUE_URL_SIGNUP_ENABLED_AUTO_CONFIRM_ON,
586+
autoRefreshToken: false,
587+
persistSession: false,
588+
storage: memoryLocalStorageAdapter(),
589+
fetch: mockFetch as unknown as typeof fetch,
590+
})
591+
592+
const { data, error } = await client.signUp({
593+
email: user.email,
594+
password: 'password123',
595+
})
596+
597+
expect(error).toBeNull()
598+
expect(data.session).toBeNull()
599+
expect(data.user).toEqual(user)
600+
})
601+
570602
test('fail to signUp() with invalid password', async () => {
571603
const { error, data } = await auth.signUp({ email: 'asd@a.aa', password: '123' })
572604

0 commit comments

Comments
 (0)