|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
| 2 | +import { createPinia, defineStore, setActivePinia } from 'pinia' |
2 | 3 | import { isReactive, isReadonly, isRef, reactive, ref, watch } from 'vue' |
3 | 4 |
|
4 | 5 | interface SessionState { |
@@ -549,6 +550,32 @@ describe('useUserSession hydration bootstrap', () => { |
549 | 550 | expect(isStateLike((store.signUp as Record<string, unknown>).email)).toBe(false) |
550 | 551 | }) |
551 | 552 |
|
| 553 | + it('keeps forwarded authClient methods callable in an actual Pinia setup store', async () => { |
| 554 | + const rawClient = createDynamicAuthProxy({ |
| 555 | + useSession: mockClient.useSession, |
| 556 | + getSession: mockClient.getSession, |
| 557 | + signOut: mockClient.signOut, |
| 558 | + signIn: createDynamicAuthProxy(), |
| 559 | + signUp: createDynamicAuthProxy(), |
| 560 | + $store: mockClient.$store, |
| 561 | + }) |
| 562 | + activeClient = rawClient |
| 563 | + setActivePinia(createPinia()) |
| 564 | + |
| 565 | + const useUserSession = await loadUseUserSession() |
| 566 | + const useAuthStore = defineStore('auth-client-forwarding', () => { |
| 567 | + const { client: authClient, ...auth } = useUserSession() |
| 568 | + return { authClient, ...auth } |
| 569 | + }) |
| 570 | + const store = useAuthStore() |
| 571 | + |
| 572 | + expect(typeof store.authClient).toBe('object') |
| 573 | + expect(typeof (store.authClient as Record<string, unknown>).sendVerificationEmail).toBe('function') |
| 574 | + expect(isRef(store.authClient as unknown)).toBe(false) |
| 575 | + expect(isReactive(store.authClient as unknown)).toBe(false) |
| 576 | + expect(isReactive((store.authClient as Record<string, unknown>).sendVerificationEmail)).toBe(false) |
| 577 | + }) |
| 578 | + |
552 | 579 | it('allows server-side auth method reads but still rejects invocation', async () => { |
553 | 580 | setRuntimeFlags({ client: false, server: true }) |
554 | 581 |
|
|
0 commit comments