@svadmin/supabase 0.8.4 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/auth-provider.ts +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svadmin/supabase",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Supabase adapters — DataProvider, AuthProvider, LiveProvider, AuditHandler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@svadmin/core": "^0.
|
|
19
|
+
"@svadmin/core": "^0.21.0",
|
|
20
20
|
"@supabase/supabase-js": "^2.0.0"
|
|
21
21
|
},
|
|
22
22
|
"license": "MIT",
|
package/src/auth-provider.ts
CHANGED
|
@@ -31,11 +31,15 @@ export function createSupabaseAuthProvider(client: SupabaseClient): AuthProvider
|
|
|
31
31
|
async getIdentity(): Promise<Identity | null> {
|
|
32
32
|
const { data: { user } } = await client.auth.getUser();
|
|
33
33
|
if (!user) return null;
|
|
34
|
+
|
|
35
|
+
const { data: { session } } = await client.auth.getSession();
|
|
36
|
+
|
|
34
37
|
return {
|
|
35
38
|
id: user.id,
|
|
36
39
|
name: user.user_metadata?.name ?? user.email?.split('@')[0] ?? 'User',
|
|
37
40
|
email: user.email,
|
|
38
41
|
avatar: user.user_metadata?.avatar_url,
|
|
42
|
+
token: session?.access_token,
|
|
39
43
|
};
|
|
40
44
|
},
|
|
41
45
|
|
|
@@ -68,6 +72,18 @@ export function createSupabaseAuthProvider(client: SupabaseClient): AuthProvider
|
|
|
68
72
|
|
|
69
73
|
async onError(error: unknown): Promise<{ redirectTo?: string; logout?: boolean }> {
|
|
70
74
|
if (error instanceof Error && error.message.includes('401')) {
|
|
75
|
+
// Pre-flight check: race-condition guard
|
|
76
|
+
// Supabase might have just refreshed the token in the background right after our fetch failed
|
|
77
|
+
const { data: { session } } = await client.auth.getSession();
|
|
78
|
+
|
|
79
|
+
if (session?.access_token) {
|
|
80
|
+
// Token is actually still valid in Supabase! The 401 was a stale race condition.
|
|
81
|
+
// We intercept and swallow the logout action so the user isn't falsely kicked.
|
|
82
|
+
return {};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Truly expired
|
|
86
|
+
await client.auth.signOut();
|
|
71
87
|
return { redirectTo: '/login', logout: true };
|
|
72
88
|
}
|
|
73
89
|
return {};
|