@fayz-ai/auth 0.5.0 → 0.6.6
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/dist/adapters/mock.d.ts.map +1 -1
- package/dist/adapters/supabase.d.ts +2 -0
- package/dist/adapters/supabase.d.ts.map +1 -1
- package/dist/context.d.ts +9 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/index.cjs +91 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +91 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -5
- package/src/adapters/mock.ts +14 -0
- package/src/adapters/supabase.ts +56 -7
- package/src/context.tsx +46 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../src/adapters/mock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAA;AAEvE,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAoDD,wBAAgB,qBAAqB,CAAC,QAAQ,GAAE,QAA4B,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../src/adapters/mock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAA;AAEvE,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAoDD,wBAAgB,qBAAqB,CAAC,QAAQ,GAAE,QAA4B,GAAG,WAAW,CAkFzF"}
|
|
@@ -4,6 +4,8 @@ export interface SupabaseAuthConfig {
|
|
|
4
4
|
supabaseUrl: string;
|
|
5
5
|
supabaseAnonKey: string;
|
|
6
6
|
supabaseClient?: SupabaseClient;
|
|
7
|
+
callbackUrl?: string;
|
|
8
|
+
resetPasswordUrl?: string;
|
|
7
9
|
}
|
|
8
10
|
export declare function createSupabaseAuthAdapter(config: SupabaseAuthConfig): AuthAdapter;
|
|
9
11
|
//# sourceMappingURL=supabase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/adapters/supabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACzE,OAAO,KAAK,EAAE,WAAW,EAAuC,MAAM,eAAe,CAAA;AAErF,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/adapters/supabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACzE,OAAO,KAAK,EAAE,WAAW,EAAuC,MAAM,eAAe,CAAA;AAErF,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAuCD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,kBAAkB,GAAG,WAAW,CA6HjF"}
|
package/dist/context.d.ts
CHANGED
|
@@ -15,6 +15,14 @@ export declare function useAuth(): {
|
|
|
15
15
|
signUp: (email: string, password: string, fullName: string) => Promise<AuthSession>;
|
|
16
16
|
signOut: () => Promise<void>;
|
|
17
17
|
signInWithOAuth: (provider: OAuthProvider) => Promise<void>;
|
|
18
|
-
resetPassword: (email: string
|
|
18
|
+
resetPassword: (email: string, options?: {
|
|
19
|
+
redirectTo?: string;
|
|
20
|
+
}) => Promise<void>;
|
|
21
|
+
updatePassword: (password: string) => Promise<AuthSession | void>;
|
|
22
|
+
handleCallback: (url?: string) => Promise<AuthSession | null>;
|
|
23
|
+
inviteUser: (email: string, options?: {
|
|
24
|
+
redirectTo?: string;
|
|
25
|
+
data?: Record<string, unknown>;
|
|
26
|
+
}) => Promise<void>;
|
|
19
27
|
};
|
|
20
28
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuD,MAAM,OAAO,CAAA;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,IAAI,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuD,MAAM,OAAO,CAAA;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,IAAI,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAwB5F,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,WAAW,CAAA;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED,wBAAgB,YAAY,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,iBAAiB,qBA6IpE;AAMD,wBAAgB,OAAO;;;;;;oBAxKL,MAAM,YAAY,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC;oBACjD,MAAM,YAAY,MAAM,YAAY,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC;mBACpE,OAAO,CAAC,IAAI,CAAC;gCACA,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC;2BACpC,MAAM,YAAY;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC;+BACvD,MAAM,KAAK,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;2BAC1C,MAAM,KAAK,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;wBACzC,MAAM,YAAY;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC;EAwLhH"}
|
package/dist/index.cjs
CHANGED
|
@@ -72,14 +72,53 @@ function createSupabaseAuthAdapter(config) {
|
|
|
72
72
|
const { error } = await supabase.auth.signInWithOAuth({
|
|
73
73
|
provider,
|
|
74
74
|
options: {
|
|
75
|
-
redirectTo: typeof window !== "undefined" ? `${window.location.origin}/auth/callback` : void 0
|
|
75
|
+
redirectTo: config.callbackUrl ?? (typeof window !== "undefined" ? `${window.location.origin}/auth/callback` : void 0)
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
if (error) throw error;
|
|
79
79
|
},
|
|
80
|
-
async resetPassword(email) {
|
|
80
|
+
async resetPassword(email, options) {
|
|
81
81
|
const { error } = await supabase.auth.resetPasswordForEmail(email, {
|
|
82
|
-
redirectTo: typeof window !== "undefined" ? `${window.location.origin}/auth/reset-password` : void 0
|
|
82
|
+
redirectTo: options?.redirectTo ?? config.resetPasswordUrl ?? (typeof window !== "undefined" ? `${window.location.origin}/auth/reset-password` : void 0)
|
|
83
|
+
});
|
|
84
|
+
if (error) throw error;
|
|
85
|
+
},
|
|
86
|
+
async updatePassword(password) {
|
|
87
|
+
const { data, error } = await supabase.auth.updateUser({ password });
|
|
88
|
+
if (error) throw error;
|
|
89
|
+
const {
|
|
90
|
+
data: { session }
|
|
91
|
+
} = await supabase.auth.getSession();
|
|
92
|
+
if (session) return mapSupabaseSession(session);
|
|
93
|
+
if (!data.user) return void 0;
|
|
94
|
+
return {
|
|
95
|
+
accessToken: "",
|
|
96
|
+
refreshToken: "",
|
|
97
|
+
expiresAt: 0,
|
|
98
|
+
user: mapSupabaseUser(data.user)
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
async handleCallback(url) {
|
|
102
|
+
const target = url ?? (typeof window !== "undefined" ? window.location.href : "");
|
|
103
|
+
const code = new URL(target).searchParams.get("code");
|
|
104
|
+
if (code) {
|
|
105
|
+
const { data, error } = await supabase.auth.exchangeCodeForSession(code);
|
|
106
|
+
if (error) throw error;
|
|
107
|
+
return data.session ? mapSupabaseSession(data.session) : null;
|
|
108
|
+
}
|
|
109
|
+
const {
|
|
110
|
+
data: { session }
|
|
111
|
+
} = await supabase.auth.getSession();
|
|
112
|
+
return session ? mapSupabaseSession(session) : null;
|
|
113
|
+
},
|
|
114
|
+
async inviteUser(email, options) {
|
|
115
|
+
const { error } = await supabase.auth.signInWithOtp({
|
|
116
|
+
email,
|
|
117
|
+
options: {
|
|
118
|
+
shouldCreateUser: true,
|
|
119
|
+
emailRedirectTo: options?.redirectTo ?? (typeof window !== "undefined" ? `${window.location.origin}/` : void 0),
|
|
120
|
+
data: options?.data
|
|
121
|
+
}
|
|
83
122
|
});
|
|
84
123
|
if (error) throw error;
|
|
85
124
|
}
|
|
@@ -179,6 +218,15 @@ function createMockAuthAdapter(mockUser = DEFAULT_MOCK_USER) {
|
|
|
179
218
|
notifyListeners(user);
|
|
180
219
|
},
|
|
181
220
|
async resetPassword(_email) {
|
|
221
|
+
},
|
|
222
|
+
async updatePassword(_password) {
|
|
223
|
+
const stored = getStored();
|
|
224
|
+
return stored?.session;
|
|
225
|
+
},
|
|
226
|
+
async handleCallback() {
|
|
227
|
+
return getStored()?.session ?? null;
|
|
228
|
+
},
|
|
229
|
+
async inviteUser(_email, _options) {
|
|
182
230
|
}
|
|
183
231
|
};
|
|
184
232
|
}
|
|
@@ -277,10 +325,44 @@ function AuthProvider({ adapter, children }) {
|
|
|
277
325
|
throw error;
|
|
278
326
|
}
|
|
279
327
|
},
|
|
280
|
-
async resetPassword(email) {
|
|
328
|
+
async resetPassword(email, options) {
|
|
329
|
+
setError(null);
|
|
330
|
+
try {
|
|
331
|
+
await adapterRef.current.resetPassword(email, options);
|
|
332
|
+
} catch (err) {
|
|
333
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
334
|
+
setError(error);
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
async updatePassword(password) {
|
|
339
|
+
setError(null);
|
|
340
|
+
try {
|
|
341
|
+
const session = await adapterRef.current.updatePassword?.(password);
|
|
342
|
+
if (session) setSession(session);
|
|
343
|
+
return session;
|
|
344
|
+
} catch (err) {
|
|
345
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
346
|
+
setError(error);
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
async handleCallback(url) {
|
|
351
|
+
setError(null);
|
|
352
|
+
try {
|
|
353
|
+
const session = await adapterRef.current.handleCallback?.(url) ?? null;
|
|
354
|
+
if (session) setSession(session);
|
|
355
|
+
return session;
|
|
356
|
+
} catch (err) {
|
|
357
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
358
|
+
setError(error);
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
async inviteUser(email, options) {
|
|
281
363
|
setError(null);
|
|
282
364
|
try {
|
|
283
|
-
await adapterRef.current.
|
|
365
|
+
await adapterRef.current.inviteUser?.(email, options);
|
|
284
366
|
} catch (err) {
|
|
285
367
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
286
368
|
setError(error);
|
|
@@ -306,7 +388,10 @@ function useAuth() {
|
|
|
306
388
|
signUp: ctx.signUp,
|
|
307
389
|
signOut: ctx.signOut,
|
|
308
390
|
signInWithOAuth: ctx.signInWithOAuth,
|
|
309
|
-
resetPassword: ctx.resetPassword
|
|
391
|
+
resetPassword: ctx.resetPassword,
|
|
392
|
+
updatePassword: ctx.updatePassword,
|
|
393
|
+
handleCallback: ctx.handleCallback,
|
|
394
|
+
inviteUser: ctx.inviteUser
|
|
310
395
|
};
|
|
311
396
|
}
|
|
312
397
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapters/supabase.ts","../src/adapters/mock.ts","../src/store.ts","../src/context.tsx"],"names":["createClient","create","createContext","useRef","useEffect","jsx","useContext"],"mappings":";;;;;;;;AASA,SAAS,gBAAgB,YAAA,EAQZ;AACX,EAAA,OAAO;AAAA,IACL,IAAI,YAAA,CAAa,EAAA;AAAA,IACjB,KAAA,EAAO,aAAa,KAAA,IAAS,EAAA;AAAA,IAC7B,QAAA,EACG,aAAa,aAAA,GAAgB,WAAW,KACxC,YAAA,CAAa,aAAA,GAAgB,MAAM,CAAA,IACpC,EAAA;AAAA,IACF,SAAA,EAAW,YAAA,CAAa,aAAA,GAAgB,YAAY;AAAA,GACtD;AACF;AAEA,SAAS,mBAAmB,OAAA,EAMZ;AACd,EAAA,OAAO;AAAA,IACL,aAAa,OAAA,CAAQ,YAAA;AAAA,IACrB,cAAc,OAAA,CAAQ,aAAA;AAAA,IACtB,SAAA,EACE,OAAA,CAAQ,UAAA,IACR,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,GAAA,EAAI,GAAI,GAAI,CAAA,IAAK,OAAA,CAAQ,UAAA,IAAc,IAAA,CAAA;AAAA,IACzD,IAAA,EAAM,eAAA,CAAgB,OAAA,CAAQ,IAAI;AAAA,GACpC;AACF;AAEO,SAAS,0BAA0B,MAAA,EAAyC;AACjF,EAAA,MAAM,WAAW,MAAA,CAAO,cAAA,IAAkBA,wBAAa,MAAA,CAAO,WAAA,EAAa,OAAO,eAAe,CAAA;AAEjG,EAAA,OAAO;AAAA,IACL,MAAM,UAAA,GAAa;AACjB,MAAA,MAAM;AAAA,QACJ,IAAA,EAAM,EAAE,OAAA;AAAQ,OAClB,GAAI,MAAM,QA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,OAAe,QAAA,EAAS,CAAA;AACvD;AAMO,SAAS,OAAA,GAAU;AACxB,EAAA,MAAM,GAAA,GAAMC,iBAAW,WAAW,CAAA;AAClC,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,MAAM,4CAA4C,CAAA;AAAA,EAC9D;AAEA,EAAA,MAAM,EAAE,IAAA,EAAM,OAAA,EAAS,WAAW,eAAA,EAAiB,KAAA,KAAU,YAAA,EAAa;AAE1E,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,OAAA;AAAA,IACA,SAAA;AAAA,IACA,eAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAQ,GAAA,CAAI,MAAA;AAAA,IACZ,QAAQ,GAAA,CAAI,MAAA;AAAA,IACZ,SAAS,GAAA,CAAI,OAAA;AAAA,IACb,iBAAiB,GAAA,CAAI,eAAA;AAAA,IACrB,eAAe,GAAA,CAAI;AAAA,GACrB;AACF","file":"index.cjs","sourcesContent":["import { createClient, type SupabaseClient } from '@supabase/supabase-js'\nimport type { AuthAdapter, AuthUser, AuthSession, AuthProvider } from '@fayz-ai/core'\n\nexport interface SupabaseAuthConfig {\n supabaseUrl: string\n supabaseAnonKey: string\n supabaseClient?: SupabaseClient\n}\n\nfunction mapSupabaseUser(supabaseUser: {\n id: string\n email?: string | null\n created_at?: string\n updated_at?: string | null\n email_confirmed_at?: string | null\n user_metadata?: Record<string, unknown>\n app_metadata?: { providers?: string[]; provider?: string }\n}): AuthUser {\n return {\n id: supabaseUser.id,\n email: supabaseUser.email ?? '',\n fullName:\n (supabaseUser.user_metadata?.['full_name'] as string | undefined) ??\n (supabaseUser.user_metadata?.['name'] as string | undefined) ??\n '',\n avatarUrl: supabaseUser.user_metadata?.['avatar_url'] as string | undefined,\n }\n}\n\nfunction mapSupabaseSession(session: {\n access_token: string\n refresh_token?: string\n expires_at?: number\n expires_in?: number\n user: Parameters<typeof mapSupabaseUser>[0]\n}): AuthSession {\n return {\n accessToken: session.access_token,\n refreshToken: session.refresh_token,\n expiresAt:\n session.expires_at ??\n Math.floor(Date.now() / 1000) + (session.expires_in ?? 3600),\n user: mapSupabaseUser(session.user),\n }\n}\n\nexport function createSupabaseAuthAdapter(config: SupabaseAuthConfig): AuthAdapter {\n const supabase = config.supabaseClient ?? createClient(config.supabaseUrl, config.supabaseAnonKey)\n\n return {\n async getSession() {\n const {\n data: { session },\n } = await supabase.auth.getSession()\n if (!session) return null\n const mapped = mapSupabaseSession(session)\n return { user: mapped.user, session: mapped }\n },\n\n onAuthStateChange(cb) {\n const {\n data: { subscription },\n } = supabase.auth.onAuthStateChange((_event, session) => {\n cb(session ? mapSupabaseUser(session.user) : null)\n })\n return () => subscription.unsubscribe()\n },\n\n async signIn(email, password) {\n const { data, error } = await supabase.auth.signInWithPassword({ email, password })\n if (error) throw error\n return mapSupabaseSession(data.session)\n },\n\n async signUp(email, password, fullName) {\n const { data, error } = await supabase.auth.signUp({\n email,\n password,\n options: { data: { full_name: fullName } },\n })\n if (error) throw error\n\n // When email confirmation is required, session is null\n if (!data.session) {\n if (!data.user) throw new Error('Signup failed: no user returned')\n return {\n accessToken: '',\n refreshToken: '',\n expiresAt: 0,\n user: mapSupabaseUser(data.user),\n }\n }\n\n return mapSupabaseSession(data.session)\n },\n\n async signOut() {\n const { error } = await supabase.auth.signOut()\n if (error) throw error\n },\n\n async signInWithOAuth(provider: AuthProvider) {\n const { error } = await supabase.auth.signInWithOAuth({\n provider: provider as 'google' | 'github' | 'apple',\n options: {\n redirectTo:\n typeof window !== 'undefined'\n ? `${window.location.origin}/auth/callback`\n : undefined,\n },\n })\n if (error) throw error\n },\n\n async resetPassword(email) {\n const { error } = await supabase.auth.resetPasswordForEmail(email, {\n redirectTo:\n typeof window !== 'undefined'\n ? `${window.location.origin}/auth/reset-password`\n : undefined,\n })\n if (error) throw error\n },\n }\n}\n","import type { AuthAdapter, AuthUser, AuthSession } from '@fayz-ai/core'\n\nexport interface MockUser {\n id: string\n email: string\n fullName: string\n role?: string\n}\n\nconst DEFAULT_MOCK_USER: MockUser = {\n id: 'mock-user-id',\n email: 'demo@fayz.dev',\n fullName: 'Demo User',\n role: 'admin',\n}\n\nconst STORAGE_KEY = 'fayz:mock-auth'\n\nfunction toAuthUser(mockUser: MockUser): AuthUser {\n return {\n id: mockUser.id,\n email: mockUser.email,\n fullName: mockUser.fullName,\n }\n}\n\nfunction createMockSession(user: AuthUser): AuthSession {\n return {\n accessToken: `mock-token-${user.id}`,\n refreshToken: `mock-refresh-${user.id}`,\n expiresAt: Math.floor(Date.now() / 1000) + 3600,\n user,\n }\n}\n\nfunction getStored(): { user: AuthUser; session: AuthSession } | null {\n try {\n if (typeof localStorage === 'undefined') return null\n const raw = localStorage.getItem(STORAGE_KEY)\n if (!raw) return null\n return JSON.parse(raw) as { user: AuthUser; session: AuthSession }\n } catch {\n return null\n }\n}\n\nfunction setStored(data: { user: AuthUser; session: AuthSession } | null): void {\n try {\n if (typeof localStorage === 'undefined') return\n if (data) {\n localStorage.setItem(STORAGE_KEY, JSON.stringify(data))\n } else {\n localStorage.removeItem(STORAGE_KEY)\n }\n } catch {\n // SSR or storage unavailable — silently skip\n }\n}\n\nexport function createMockAuthAdapter(mockUser: MockUser = DEFAULT_MOCK_USER): AuthAdapter {\n const listeners = new Set<(user: AuthUser | null) => void>()\n\n function notifyListeners(user: AuthUser | null): void {\n for (const cb of listeners) cb(user)\n }\n\n return {\n async getSession() {\n return getStored()\n },\n\n onAuthStateChange(cb) {\n listeners.add(cb)\n return () => {\n listeners.delete(cb)\n }\n },\n\n async signIn(email, _password) {\n // Mock accepts any credentials, but the identity FOLLOWS the email —\n // storefront customers and saas users keep their own purchase/session\n // history instead of all becoming the configured demo user.\n const stored = getStored()\n const user: AuthUser =\n stored && stored.user.email === email\n ? stored.user\n : {\n id: email === mockUser.email ? mockUser.id : `mock-${email}`,\n email,\n fullName: email === mockUser.email ? mockUser.fullName : (email.split('@')[0] ?? 'Cliente'),\n }\n const session = createMockSession(user)\n setStored({ user, session })\n notifyListeners(user)\n return session\n },\n\n async signUp(email, _password, fullName) {\n // Mock signup creates a user from the provided details\n const user: AuthUser = {\n id: `mock-${email}`,\n email,\n fullName: fullName || (email.split('@')[0] ?? 'Cliente'),\n }\n const session = createMockSession(user)\n setStored({ user, session })\n notifyListeners(user)\n return session\n },\n\n async signOut() {\n setStored(null)\n notifyListeners(null)\n },\n\n async signInWithOAuth(_provider) {\n // Mock OAuth signs in as the configured user\n const user = toAuthUser(mockUser)\n const session = createMockSession(user)\n setStored({ user, session })\n notifyListeners(user)\n },\n\n async resetPassword(_email) {\n // No-op in mock\n },\n }\n}\n","import { create } from 'zustand'\nimport type { AuthUser, AuthSession } from '@fayz-ai/core'\n\nexport interface AuthState {\n user: AuthUser | null\n session: AuthSession | null\n isLoading: boolean\n isAuthenticated: boolean\n error: Error | null\n}\n\nexport interface AuthStore extends AuthState {\n setUser: (user: AuthUser | null) => void\n setSession: (session: AuthSession | null) => void\n setLoading: (isLoading: boolean) => void\n setError: (error: Error | null) => void\n reset: () => void\n}\n\nconst initialState: AuthState = {\n user: null,\n session: null,\n isLoading: true,\n isAuthenticated: false,\n error: null,\n}\n\nexport const useAuthStore = create<AuthStore>((set) => ({\n ...initialState,\n\n setUser: (user) =>\n set({ user, isAuthenticated: user !== null }),\n\n setSession: (session) =>\n set({\n session,\n user: session?.user ?? null,\n isAuthenticated: session !== null,\n }),\n\n setLoading: (isLoading) => set({ isLoading }),\n\n setError: (error) => set({ error }),\n\n reset: () => set(initialState),\n}))\n","import React, { createContext, useContext, useEffect, useRef } from 'react'\nimport type { AuthAdapter, AuthProvider as OAuthProvider, AuthSession } from '@fayz-ai/core'\nimport { useAuthStore } from './store'\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\ninterface AuthContextValue {\n signIn: (email: string, password: string) => Promise<AuthSession>\n signUp: (email: string, password: string, fullName: string) => Promise<AuthSession>\n signOut: () => Promise<void>\n signInWithOAuth: (provider: OAuthProvider) => Promise<void>\n resetPassword: (email: string) => Promise<void>\n}\n\nconst AuthContext = createContext<AuthContextValue | null>(null)\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\nexport interface AuthProviderProps {\n adapter: AuthAdapter\n children: React.ReactNode\n}\n\nexport function AuthProvider({ adapter, children }: AuthProviderProps) {\n const { setSession, setLoading, setError, reset } = useAuthStore()\n\n // Keep a stable ref to the adapter so the effect only runs once on mount\n const adapterRef = useRef(adapter)\n adapterRef.current = adapter\n\n useEffect(() => {\n let unsubscribe: (() => void) | undefined\n\n async function init() {\n try {\n setLoading(true)\n const result = await adapterRef.current.getSession()\n setSession(result?.session ?? null)\n } catch (err) {\n setError(err instanceof Error ? err : new Error(String(err)))\n } finally {\n setLoading(false)\n }\n\n // Subscribe to future auth state changes\n unsubscribe = adapterRef.current.onAuthStateChange((user) => {\n if (!user) {\n reset()\n // Keep isLoading false after an explicit sign-out\n setLoading(false)\n }\n // Positive auth state changes are handled via setSession after signIn/signUp\n })\n }\n\n void init()\n\n return () => {\n unsubscribe?.()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n const value: AuthContextValue = {\n async signIn(email, password) {\n setError(null)\n try {\n const session = await adapterRef.current.signIn(email, password)\n setSession(session)\n return session\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async signUp(email, password, fullName) {\n setError(null)\n try {\n const session = await adapterRef.current.signUp(email, password, fullName)\n setSession(session)\n return session\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async signOut() {\n setError(null)\n try {\n await adapterRef.current.signOut()\n reset()\n setLoading(false)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async signInWithOAuth(provider) {\n setError(null)\n try {\n await adapterRef.current.signInWithOAuth(provider)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async resetPassword(email) {\n setError(null)\n try {\n await adapterRef.current.resetPassword(email)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n }\n\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\nexport function useAuth() {\n const ctx = useContext(AuthContext)\n if (!ctx) {\n throw new Error('useAuth must be used inside <AuthProvider>')\n }\n\n const { user, session, isLoading, isAuthenticated, error } = useAuthStore()\n\n return {\n user,\n session,\n isLoading,\n isAuthenticated,\n error,\n signIn: ctx.signIn,\n signUp: ctx.signUp,\n signOut: ctx.signOut,\n signInWithOAuth: ctx.signInWithOAuth,\n resetPassword: ctx.resetPassword,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/adapters/supabase.ts","../src/adapters/mock.ts","../src/store.ts","../src/context.tsx"],"names":["createClient","create","createContext","useRef","useEffect","jsx","useContext"],"mappings":";;;;;;;;AAWA,SAAS,gBAAgB,YAAA,EAQZ;AACX,EAAA,OAAO;AAAA,IACL,IAAI,YAAA,CAAa,EAAA;AAAA,IACjB,KAAA,EAAO,aAAa,KAAA,IAAS,EAAA;AAAA,IAC7B,QAAA,EACG,aAAa,aAAA,GAAgB,WAAW,KACxC,YAAA,CAAa,aAAA,GAAgB,MAAM,CAAA,IACpC,EAAA;AAAA,IACF,SAAA,EAAW,YAAA,CAAa,aAAA,GAAgB,YAAY;AAAA,GACtD;AACF;AAEA,SAAS,mBAAmB,OAAA,EAMZ;AACd,EAAA,OAAO;AAAA,IACL,aAAa,OAAA,CAAQ,YAAA;AAAA,IACrB,cAAc,OAAA,CAAQ,aAAA;AAAA,IACtB,SAAA,EACE,OAAA,CAAQ,UAAA,IACR,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,GAAA,EAAI,GAAI,GAAI,CAAA,IAAK,OAAA,CAAQ,UAAA,IAAc,IAAA,CAAA;AAAA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,GAAM,IAAI,KAAA,CAAM,MAAA,CAAO,GAAG,CAAC,CAAA;AAChE,QAAA,QAAA,CAAS,KAAK,CAAA;AACd,QAAA,MAAM,KAAA;AAAA,MACR;AAAA,IACF;AAAA,GACF;AAEA,EAAA,uBAAOC,cAAA,CAAC,WAAA,CAAY,QAAA,EAAZ,EAAqB,OAAe,QAAA,EAAS,CAAA;AACvD;AAMO,SAAS,OAAA,GAAU;AACxB,EAAA,MAAM,GAAA,GAAMC,iBAAW,WAAW,CAAA;AAClC,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,MAAM,4CAA4C,CAAA;AAAA,EAC9D;AAEA,EAAA,MAAM,EAAE,IAAA,EAAM,OAAA,EAAS,WAAW,eAAA,EAAiB,KAAA,KAAU,YAAA,EAAa;AAE1E,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,OAAA;AAAA,IACA,SAAA;AAAA,IACA,eAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAQ,GAAA,CAAI,MAAA;AAAA,IACZ,QAAQ,GAAA,CAAI,MAAA;AAAA,IACZ,SAAS,GAAA,CAAI,OAAA;AAAA,IACb,iBAAiB,GAAA,CAAI,eAAA;AAAA,IACrB,eAAe,GAAA,CAAI,aAAA;AAAA,IACnB,gBAAgB,GAAA,CAAI,cAAA;AAAA,IACpB,gBAAgB,GAAA,CAAI,cAAA;AAAA,IACpB,YAAY,GAAA,CAAI;AAAA,GAClB;AACF","file":"index.cjs","sourcesContent":["import { createClient, type SupabaseClient } from '@supabase/supabase-js'\nimport type { AuthAdapter, AuthUser, AuthSession, AuthProvider } from '@fayz-ai/core'\n\nexport interface SupabaseAuthConfig {\n supabaseUrl: string\n supabaseAnonKey: string\n supabaseClient?: SupabaseClient\n callbackUrl?: string\n resetPasswordUrl?: string\n}\n\nfunction mapSupabaseUser(supabaseUser: {\n id: string\n email?: string | null\n created_at?: string\n updated_at?: string | null\n email_confirmed_at?: string | null\n user_metadata?: Record<string, unknown>\n app_metadata?: { providers?: string[]; provider?: string }\n}): AuthUser {\n return {\n id: supabaseUser.id,\n email: supabaseUser.email ?? '',\n fullName:\n (supabaseUser.user_metadata?.['full_name'] as string | undefined) ??\n (supabaseUser.user_metadata?.['name'] as string | undefined) ??\n '',\n avatarUrl: supabaseUser.user_metadata?.['avatar_url'] as string | undefined,\n }\n}\n\nfunction mapSupabaseSession(session: {\n access_token: string\n refresh_token?: string\n expires_at?: number\n expires_in?: number\n user: Parameters<typeof mapSupabaseUser>[0]\n}): AuthSession {\n return {\n accessToken: session.access_token,\n refreshToken: session.refresh_token,\n expiresAt:\n session.expires_at ??\n Math.floor(Date.now() / 1000) + (session.expires_in ?? 3600),\n user: mapSupabaseUser(session.user),\n }\n}\n\nexport function createSupabaseAuthAdapter(config: SupabaseAuthConfig): AuthAdapter {\n const supabase = config.supabaseClient ?? createClient(config.supabaseUrl, config.supabaseAnonKey)\n\n return {\n async getSession() {\n const {\n data: { session },\n } = await supabase.auth.getSession()\n if (!session) return null\n const mapped = mapSupabaseSession(session)\n return { user: mapped.user, session: mapped }\n },\n\n onAuthStateChange(cb) {\n const {\n data: { subscription },\n } = supabase.auth.onAuthStateChange((_event, session) => {\n cb(session ? mapSupabaseUser(session.user) : null)\n })\n return () => subscription.unsubscribe()\n },\n\n async signIn(email, password) {\n const { data, error } = await supabase.auth.signInWithPassword({ email, password })\n if (error) throw error\n return mapSupabaseSession(data.session)\n },\n\n async signUp(email, password, fullName) {\n const { data, error } = await supabase.auth.signUp({\n email,\n password,\n options: { data: { full_name: fullName } },\n })\n if (error) throw error\n\n // When email confirmation is required, session is null\n if (!data.session) {\n if (!data.user) throw new Error('Signup failed: no user returned')\n return {\n accessToken: '',\n refreshToken: '',\n expiresAt: 0,\n user: mapSupabaseUser(data.user),\n }\n }\n\n return mapSupabaseSession(data.session)\n },\n\n async signOut() {\n const { error } = await supabase.auth.signOut()\n if (error) throw error\n },\n\n async signInWithOAuth(provider: AuthProvider) {\n const { error } = await supabase.auth.signInWithOAuth({\n provider: provider as 'google' | 'github' | 'apple',\n options: {\n redirectTo:\n config.callbackUrl ??\n (typeof window !== 'undefined' ? `${window.location.origin}/auth/callback` : undefined),\n },\n })\n if (error) throw error\n },\n\n async resetPassword(email, options) {\n const { error } = await supabase.auth.resetPasswordForEmail(email, {\n redirectTo:\n options?.redirectTo ??\n config.resetPasswordUrl ??\n (typeof window !== 'undefined' ? `${window.location.origin}/auth/reset-password` : undefined),\n })\n if (error) throw error\n },\n\n async updatePassword(password) {\n const { data, error } = await supabase.auth.updateUser({ password })\n if (error) throw error\n const {\n data: { session },\n } = await supabase.auth.getSession()\n if (session) return mapSupabaseSession(session)\n if (!data.user) return undefined\n return {\n accessToken: '',\n refreshToken: '',\n expiresAt: 0,\n user: mapSupabaseUser(data.user),\n }\n },\n\n async handleCallback(url) {\n const target = url ?? (typeof window !== 'undefined' ? window.location.href : '')\n const code = new URL(target).searchParams.get('code')\n if (code) {\n const { data, error } = await supabase.auth.exchangeCodeForSession(code)\n if (error) throw error\n return data.session ? mapSupabaseSession(data.session) : null\n }\n const {\n data: { session },\n } = await supabase.auth.getSession()\n return session ? mapSupabaseSession(session) : null\n },\n\n async inviteUser(email, options) {\n // Native, edge-function-free invite: a passwordless magic link. Sends the\n // e-mail + creates the auth user (anon-callable, no service-role/admin).\n // Membership is NOT granted from `data` (a client could forge it) — the\n // accept-time trigger trusts the RLS-protected saas_core.invitations row.\n const { error } = await supabase.auth.signInWithOtp({\n email,\n options: {\n shouldCreateUser: true,\n emailRedirectTo:\n options?.redirectTo ??\n (typeof window !== 'undefined' ? `${window.location.origin}/` : undefined),\n data: options?.data,\n },\n })\n if (error) throw error\n },\n }\n}\n","import type { AuthAdapter, AuthUser, AuthSession } from '@fayz-ai/core'\n\nexport interface MockUser {\n id: string\n email: string\n fullName: string\n role?: string\n}\n\nconst DEFAULT_MOCK_USER: MockUser = {\n id: 'mock-user-id',\n email: 'demo@fayz.dev',\n fullName: 'Demo User',\n role: 'admin',\n}\n\nconst STORAGE_KEY = 'fayz:mock-auth'\n\nfunction toAuthUser(mockUser: MockUser): AuthUser {\n return {\n id: mockUser.id,\n email: mockUser.email,\n fullName: mockUser.fullName,\n }\n}\n\nfunction createMockSession(user: AuthUser): AuthSession {\n return {\n accessToken: `mock-token-${user.id}`,\n refreshToken: `mock-refresh-${user.id}`,\n expiresAt: Math.floor(Date.now() / 1000) + 3600,\n user,\n }\n}\n\nfunction getStored(): { user: AuthUser; session: AuthSession } | null {\n try {\n if (typeof localStorage === 'undefined') return null\n const raw = localStorage.getItem(STORAGE_KEY)\n if (!raw) return null\n return JSON.parse(raw) as { user: AuthUser; session: AuthSession }\n } catch {\n return null\n }\n}\n\nfunction setStored(data: { user: AuthUser; session: AuthSession } | null): void {\n try {\n if (typeof localStorage === 'undefined') return\n if (data) {\n localStorage.setItem(STORAGE_KEY, JSON.stringify(data))\n } else {\n localStorage.removeItem(STORAGE_KEY)\n }\n } catch {\n // SSR or storage unavailable — silently skip\n }\n}\n\nexport function createMockAuthAdapter(mockUser: MockUser = DEFAULT_MOCK_USER): AuthAdapter {\n const listeners = new Set<(user: AuthUser | null) => void>()\n\n function notifyListeners(user: AuthUser | null): void {\n for (const cb of listeners) cb(user)\n }\n\n return {\n async getSession() {\n return getStored()\n },\n\n onAuthStateChange(cb) {\n listeners.add(cb)\n return () => {\n listeners.delete(cb)\n }\n },\n\n async signIn(email, _password) {\n // Mock accepts any credentials, but the identity FOLLOWS the email —\n // storefront customers and saas users keep their own purchase/session\n // history instead of all becoming the configured demo user.\n const stored = getStored()\n const user: AuthUser =\n stored && stored.user.email === email\n ? stored.user\n : {\n id: email === mockUser.email ? mockUser.id : `mock-${email}`,\n email,\n fullName: email === mockUser.email ? mockUser.fullName : (email.split('@')[0] ?? 'Cliente'),\n }\n const session = createMockSession(user)\n setStored({ user, session })\n notifyListeners(user)\n return session\n },\n\n async signUp(email, _password, fullName) {\n // Mock signup creates a user from the provided details\n const user: AuthUser = {\n id: `mock-${email}`,\n email,\n fullName: fullName || (email.split('@')[0] ?? 'Cliente'),\n }\n const session = createMockSession(user)\n setStored({ user, session })\n notifyListeners(user)\n return session\n },\n\n async signOut() {\n setStored(null)\n notifyListeners(null)\n },\n\n async signInWithOAuth(_provider) {\n // Mock OAuth signs in as the configured user\n const user = toAuthUser(mockUser)\n const session = createMockSession(user)\n setStored({ user, session })\n notifyListeners(user)\n },\n\n async resetPassword(_email) {\n // No-op in mock\n },\n\n async updatePassword(_password) {\n const stored = getStored()\n return stored?.session\n },\n\n async handleCallback() {\n return getStored()?.session ?? null\n },\n\n async inviteUser(_email, _options) {\n // No admin path in mock — the org mock adapter still records the pending\n // invite so the Team UI shows it. Delivery is a no-op locally.\n },\n }\n}\n","import { create } from 'zustand'\nimport type { AuthUser, AuthSession } from '@fayz-ai/core'\n\nexport interface AuthState {\n user: AuthUser | null\n session: AuthSession | null\n isLoading: boolean\n isAuthenticated: boolean\n error: Error | null\n}\n\nexport interface AuthStore extends AuthState {\n setUser: (user: AuthUser | null) => void\n setSession: (session: AuthSession | null) => void\n setLoading: (isLoading: boolean) => void\n setError: (error: Error | null) => void\n reset: () => void\n}\n\nconst initialState: AuthState = {\n user: null,\n session: null,\n isLoading: true,\n isAuthenticated: false,\n error: null,\n}\n\nexport const useAuthStore = create<AuthStore>((set) => ({\n ...initialState,\n\n setUser: (user) =>\n set({ user, isAuthenticated: user !== null }),\n\n setSession: (session) =>\n set({\n session,\n user: session?.user ?? null,\n isAuthenticated: session !== null,\n }),\n\n setLoading: (isLoading) => set({ isLoading }),\n\n setError: (error) => set({ error }),\n\n reset: () => set(initialState),\n}))\n","import React, { createContext, useContext, useEffect, useRef } from 'react'\nimport type { AuthAdapter, AuthProvider as OAuthProvider, AuthSession } from '@fayz-ai/core'\nimport { useAuthStore } from './store'\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\ninterface AuthContextValue {\n signIn: (email: string, password: string) => Promise<AuthSession>\n signUp: (email: string, password: string, fullName: string) => Promise<AuthSession>\n signOut: () => Promise<void>\n signInWithOAuth: (provider: OAuthProvider) => Promise<void>\n resetPassword: (email: string, options?: { redirectTo?: string }) => Promise<void>\n updatePassword: (password: string) => Promise<AuthSession | void>\n handleCallback: (url?: string) => Promise<AuthSession | null>\n inviteUser: (email: string, options?: { redirectTo?: string; data?: Record<string, unknown> }) => Promise<void>\n}\n\nconst AuthContext = createContext<AuthContextValue | null>(null)\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\nexport interface AuthProviderProps {\n adapter: AuthAdapter\n children: React.ReactNode\n}\n\nexport function AuthProvider({ adapter, children }: AuthProviderProps) {\n const { setSession, setLoading, setError, reset } = useAuthStore()\n\n // Keep a stable ref to the adapter so the effect only runs once on mount\n const adapterRef = useRef(adapter)\n adapterRef.current = adapter\n\n useEffect(() => {\n let unsubscribe: (() => void) | undefined\n\n async function init() {\n try {\n setLoading(true)\n const result = await adapterRef.current.getSession()\n setSession(result?.session ?? null)\n } catch (err) {\n setError(err instanceof Error ? err : new Error(String(err)))\n } finally {\n setLoading(false)\n }\n\n // Subscribe to future auth state changes\n unsubscribe = adapterRef.current.onAuthStateChange((user) => {\n if (!user) {\n reset()\n // Keep isLoading false after an explicit sign-out\n setLoading(false)\n }\n // Positive auth state changes are handled via setSession after signIn/signUp\n })\n }\n\n void init()\n\n return () => {\n unsubscribe?.()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n const value: AuthContextValue = {\n async signIn(email, password) {\n setError(null)\n try {\n const session = await adapterRef.current.signIn(email, password)\n setSession(session)\n return session\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async signUp(email, password, fullName) {\n setError(null)\n try {\n const session = await adapterRef.current.signUp(email, password, fullName)\n setSession(session)\n return session\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async signOut() {\n setError(null)\n try {\n await adapterRef.current.signOut()\n reset()\n setLoading(false)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async signInWithOAuth(provider) {\n setError(null)\n try {\n await adapterRef.current.signInWithOAuth(provider)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async resetPassword(email, options) {\n setError(null)\n try {\n await adapterRef.current.resetPassword(email, options)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async updatePassword(password) {\n setError(null)\n try {\n const session = await adapterRef.current.updatePassword?.(password)\n if (session) setSession(session)\n return session\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async handleCallback(url) {\n setError(null)\n try {\n const session = await adapterRef.current.handleCallback?.(url) ?? null\n if (session) setSession(session)\n return session\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async inviteUser(email, options) {\n setError(null)\n try {\n await adapterRef.current.inviteUser?.(email, options)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n }\n\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\nexport function useAuth() {\n const ctx = useContext(AuthContext)\n if (!ctx) {\n throw new Error('useAuth must be used inside <AuthProvider>')\n }\n\n const { user, session, isLoading, isAuthenticated, error } = useAuthStore()\n\n return {\n user,\n session,\n isLoading,\n isAuthenticated,\n error,\n signIn: ctx.signIn,\n signUp: ctx.signUp,\n signOut: ctx.signOut,\n signInWithOAuth: ctx.signInWithOAuth,\n resetPassword: ctx.resetPassword,\n updatePassword: ctx.updatePassword,\n handleCallback: ctx.handleCallback,\n inviteUser: ctx.inviteUser,\n }\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -70,14 +70,53 @@ function createSupabaseAuthAdapter(config) {
|
|
|
70
70
|
const { error } = await supabase.auth.signInWithOAuth({
|
|
71
71
|
provider,
|
|
72
72
|
options: {
|
|
73
|
-
redirectTo: typeof window !== "undefined" ? `${window.location.origin}/auth/callback` : void 0
|
|
73
|
+
redirectTo: config.callbackUrl ?? (typeof window !== "undefined" ? `${window.location.origin}/auth/callback` : void 0)
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
if (error) throw error;
|
|
77
77
|
},
|
|
78
|
-
async resetPassword(email) {
|
|
78
|
+
async resetPassword(email, options) {
|
|
79
79
|
const { error } = await supabase.auth.resetPasswordForEmail(email, {
|
|
80
|
-
redirectTo: typeof window !== "undefined" ? `${window.location.origin}/auth/reset-password` : void 0
|
|
80
|
+
redirectTo: options?.redirectTo ?? config.resetPasswordUrl ?? (typeof window !== "undefined" ? `${window.location.origin}/auth/reset-password` : void 0)
|
|
81
|
+
});
|
|
82
|
+
if (error) throw error;
|
|
83
|
+
},
|
|
84
|
+
async updatePassword(password) {
|
|
85
|
+
const { data, error } = await supabase.auth.updateUser({ password });
|
|
86
|
+
if (error) throw error;
|
|
87
|
+
const {
|
|
88
|
+
data: { session }
|
|
89
|
+
} = await supabase.auth.getSession();
|
|
90
|
+
if (session) return mapSupabaseSession(session);
|
|
91
|
+
if (!data.user) return void 0;
|
|
92
|
+
return {
|
|
93
|
+
accessToken: "",
|
|
94
|
+
refreshToken: "",
|
|
95
|
+
expiresAt: 0,
|
|
96
|
+
user: mapSupabaseUser(data.user)
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
async handleCallback(url) {
|
|
100
|
+
const target = url ?? (typeof window !== "undefined" ? window.location.href : "");
|
|
101
|
+
const code = new URL(target).searchParams.get("code");
|
|
102
|
+
if (code) {
|
|
103
|
+
const { data, error } = await supabase.auth.exchangeCodeForSession(code);
|
|
104
|
+
if (error) throw error;
|
|
105
|
+
return data.session ? mapSupabaseSession(data.session) : null;
|
|
106
|
+
}
|
|
107
|
+
const {
|
|
108
|
+
data: { session }
|
|
109
|
+
} = await supabase.auth.getSession();
|
|
110
|
+
return session ? mapSupabaseSession(session) : null;
|
|
111
|
+
},
|
|
112
|
+
async inviteUser(email, options) {
|
|
113
|
+
const { error } = await supabase.auth.signInWithOtp({
|
|
114
|
+
email,
|
|
115
|
+
options: {
|
|
116
|
+
shouldCreateUser: true,
|
|
117
|
+
emailRedirectTo: options?.redirectTo ?? (typeof window !== "undefined" ? `${window.location.origin}/` : void 0),
|
|
118
|
+
data: options?.data
|
|
119
|
+
}
|
|
81
120
|
});
|
|
82
121
|
if (error) throw error;
|
|
83
122
|
}
|
|
@@ -177,6 +216,15 @@ function createMockAuthAdapter(mockUser = DEFAULT_MOCK_USER) {
|
|
|
177
216
|
notifyListeners(user);
|
|
178
217
|
},
|
|
179
218
|
async resetPassword(_email) {
|
|
219
|
+
},
|
|
220
|
+
async updatePassword(_password) {
|
|
221
|
+
const stored = getStored();
|
|
222
|
+
return stored?.session;
|
|
223
|
+
},
|
|
224
|
+
async handleCallback() {
|
|
225
|
+
return getStored()?.session ?? null;
|
|
226
|
+
},
|
|
227
|
+
async inviteUser(_email, _options) {
|
|
180
228
|
}
|
|
181
229
|
};
|
|
182
230
|
}
|
|
@@ -275,10 +323,44 @@ function AuthProvider({ adapter, children }) {
|
|
|
275
323
|
throw error;
|
|
276
324
|
}
|
|
277
325
|
},
|
|
278
|
-
async resetPassword(email) {
|
|
326
|
+
async resetPassword(email, options) {
|
|
327
|
+
setError(null);
|
|
328
|
+
try {
|
|
329
|
+
await adapterRef.current.resetPassword(email, options);
|
|
330
|
+
} catch (err) {
|
|
331
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
332
|
+
setError(error);
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
async updatePassword(password) {
|
|
337
|
+
setError(null);
|
|
338
|
+
try {
|
|
339
|
+
const session = await adapterRef.current.updatePassword?.(password);
|
|
340
|
+
if (session) setSession(session);
|
|
341
|
+
return session;
|
|
342
|
+
} catch (err) {
|
|
343
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
344
|
+
setError(error);
|
|
345
|
+
throw error;
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
async handleCallback(url) {
|
|
349
|
+
setError(null);
|
|
350
|
+
try {
|
|
351
|
+
const session = await adapterRef.current.handleCallback?.(url) ?? null;
|
|
352
|
+
if (session) setSession(session);
|
|
353
|
+
return session;
|
|
354
|
+
} catch (err) {
|
|
355
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
356
|
+
setError(error);
|
|
357
|
+
throw error;
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
async inviteUser(email, options) {
|
|
279
361
|
setError(null);
|
|
280
362
|
try {
|
|
281
|
-
await adapterRef.current.
|
|
363
|
+
await adapterRef.current.inviteUser?.(email, options);
|
|
282
364
|
} catch (err) {
|
|
283
365
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
284
366
|
setError(error);
|
|
@@ -304,7 +386,10 @@ function useAuth() {
|
|
|
304
386
|
signUp: ctx.signUp,
|
|
305
387
|
signOut: ctx.signOut,
|
|
306
388
|
signInWithOAuth: ctx.signInWithOAuth,
|
|
307
|
-
resetPassword: ctx.resetPassword
|
|
389
|
+
resetPassword: ctx.resetPassword,
|
|
390
|
+
updatePassword: ctx.updatePassword,
|
|
391
|
+
handleCallback: ctx.handleCallback,
|
|
392
|
+
inviteUser: ctx.inviteUser
|
|
308
393
|
};
|
|
309
394
|
}
|
|
310
395
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapters/supabase.ts","../src/adapters/mock.ts","../src/store.ts","../src/context.tsx"],"names":[],"mappings":";;;;;;AASA,SAAS,gBAAgB,YAAA,EAQZ;AACX,EAAA,OAAO;AAAA,IACL,IAAI,YAAA,CAAa,EAAA;AAAA,IACjB,KAAA,EAAO,aAAa,KAAA,IAAS,EAAA;AAAA,IAC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MAAA;AAAA,IACZ,SAAS,GAAA,CAAI,OAAA;AAAA,IACb,iBAAiB,GAAA,CAAI,eAAA;AAAA,IACrB,eAAe,GAAA,CAAI;AAAA,GACrB;AACF","file":"index.js","sourcesContent":["import { createClient, type SupabaseClient } from '@supabase/supabase-js'\nimport type { AuthAdapter, AuthUser, AuthSession, AuthProvider } from '@fayz-ai/core'\n\nexport interface SupabaseAuthConfig {\n supabaseUrl: string\n supabaseAnonKey: string\n supabaseClient?: SupabaseClient\n}\n\nfunction mapSupabaseUser(supabaseUser: {\n id: string\n email?: string | null\n created_at?: string\n updated_at?: string | null\n email_confirmed_at?: string | null\n user_metadata?: Record<string, unknown>\n app_metadata?: { providers?: string[]; provider?: string }\n}): AuthUser {\n return {\n id: supabaseUser.id,\n email: supabaseUser.email ?? '',\n fullName:\n (supabaseUser.user_metadata?.['full_name'] as string | undefined) ??\n (supabaseUser.user_metadata?.['name'] as string | undefined) ??\n '',\n avatarUrl: supabaseUser.user_metadata?.['avatar_url'] as string | undefined,\n }\n}\n\nfunction mapSupabaseSession(session: {\n access_token: string\n refresh_token?: string\n expires_at?: number\n expires_in?: number\n user: Parameters<typeof mapSupabaseUser>[0]\n}): AuthSession {\n return {\n accessToken: session.access_token,\n refreshToken: session.refresh_token,\n expiresAt:\n session.expires_at ??\n Math.floor(Date.now() / 1000) + (session.expires_in ?? 3600),\n user: mapSupabaseUser(session.user),\n }\n}\n\nexport function createSupabaseAuthAdapter(config: SupabaseAuthConfig): AuthAdapter {\n const supabase = config.supabaseClient ?? createClient(config.supabaseUrl, config.supabaseAnonKey)\n\n return {\n async getSession() {\n const {\n data: { session },\n } = await supabase.auth.getSession()\n if (!session) return null\n const mapped = mapSupabaseSession(session)\n return { user: mapped.user, session: mapped }\n },\n\n onAuthStateChange(cb) {\n const {\n data: { subscription },\n } = supabase.auth.onAuthStateChange((_event, session) => {\n cb(session ? mapSupabaseUser(session.user) : null)\n })\n return () => subscription.unsubscribe()\n },\n\n async signIn(email, password) {\n const { data, error } = await supabase.auth.signInWithPassword({ email, password })\n if (error) throw error\n return mapSupabaseSession(data.session)\n },\n\n async signUp(email, password, fullName) {\n const { data, error } = await supabase.auth.signUp({\n email,\n password,\n options: { data: { full_name: fullName } },\n })\n if (error) throw error\n\n // When email confirmation is required, session is null\n if (!data.session) {\n if (!data.user) throw new Error('Signup failed: no user returned')\n return {\n accessToken: '',\n refreshToken: '',\n expiresAt: 0,\n user: mapSupabaseUser(data.user),\n }\n }\n\n return mapSupabaseSession(data.session)\n },\n\n async signOut() {\n const { error } = await supabase.auth.signOut()\n if (error) throw error\n },\n\n async signInWithOAuth(provider: AuthProvider) {\n const { error } = await supabase.auth.signInWithOAuth({\n provider: provider as 'google' | 'github' | 'apple',\n options: {\n redirectTo:\n typeof window !== 'undefined'\n ? `${window.location.origin}/auth/callback`\n : undefined,\n },\n })\n if (error) throw error\n },\n\n async resetPassword(email) {\n const { error } = await supabase.auth.resetPasswordForEmail(email, {\n redirectTo:\n typeof window !== 'undefined'\n ? `${window.location.origin}/auth/reset-password`\n : undefined,\n })\n if (error) throw error\n },\n }\n}\n","import type { AuthAdapter, AuthUser, AuthSession } from '@fayz-ai/core'\n\nexport interface MockUser {\n id: string\n email: string\n fullName: string\n role?: string\n}\n\nconst DEFAULT_MOCK_USER: MockUser = {\n id: 'mock-user-id',\n email: 'demo@fayz.dev',\n fullName: 'Demo User',\n role: 'admin',\n}\n\nconst STORAGE_KEY = 'fayz:mock-auth'\n\nfunction toAuthUser(mockUser: MockUser): AuthUser {\n return {\n id: mockUser.id,\n email: mockUser.email,\n fullName: mockUser.fullName,\n }\n}\n\nfunction createMockSession(user: AuthUser): AuthSession {\n return {\n accessToken: `mock-token-${user.id}`,\n refreshToken: `mock-refresh-${user.id}`,\n expiresAt: Math.floor(Date.now() / 1000) + 3600,\n user,\n }\n}\n\nfunction getStored(): { user: AuthUser; session: AuthSession } | null {\n try {\n if (typeof localStorage === 'undefined') return null\n const raw = localStorage.getItem(STORAGE_KEY)\n if (!raw) return null\n return JSON.parse(raw) as { user: AuthUser; session: AuthSession }\n } catch {\n return null\n }\n}\n\nfunction setStored(data: { user: AuthUser; session: AuthSession } | null): void {\n try {\n if (typeof localStorage === 'undefined') return\n if (data) {\n localStorage.setItem(STORAGE_KEY, JSON.stringify(data))\n } else {\n localStorage.removeItem(STORAGE_KEY)\n }\n } catch {\n // SSR or storage unavailable — silently skip\n }\n}\n\nexport function createMockAuthAdapter(mockUser: MockUser = DEFAULT_MOCK_USER): AuthAdapter {\n const listeners = new Set<(user: AuthUser | null) => void>()\n\n function notifyListeners(user: AuthUser | null): void {\n for (const cb of listeners) cb(user)\n }\n\n return {\n async getSession() {\n return getStored()\n },\n\n onAuthStateChange(cb) {\n listeners.add(cb)\n return () => {\n listeners.delete(cb)\n }\n },\n\n async signIn(email, _password) {\n // Mock accepts any credentials, but the identity FOLLOWS the email —\n // storefront customers and saas users keep their own purchase/session\n // history instead of all becoming the configured demo user.\n const stored = getStored()\n const user: AuthUser =\n stored && stored.user.email === email\n ? stored.user\n : {\n id: email === mockUser.email ? mockUser.id : `mock-${email}`,\n email,\n fullName: email === mockUser.email ? mockUser.fullName : (email.split('@')[0] ?? 'Cliente'),\n }\n const session = createMockSession(user)\n setStored({ user, session })\n notifyListeners(user)\n return session\n },\n\n async signUp(email, _password, fullName) {\n // Mock signup creates a user from the provided details\n const user: AuthUser = {\n id: `mock-${email}`,\n email,\n fullName: fullName || (email.split('@')[0] ?? 'Cliente'),\n }\n const session = createMockSession(user)\n setStored({ user, session })\n notifyListeners(user)\n return session\n },\n\n async signOut() {\n setStored(null)\n notifyListeners(null)\n },\n\n async signInWithOAuth(_provider) {\n // Mock OAuth signs in as the configured user\n const user = toAuthUser(mockUser)\n const session = createMockSession(user)\n setStored({ user, session })\n notifyListeners(user)\n },\n\n async resetPassword(_email) {\n // No-op in mock\n },\n }\n}\n","import { create } from 'zustand'\nimport type { AuthUser, AuthSession } from '@fayz-ai/core'\n\nexport interface AuthState {\n user: AuthUser | null\n session: AuthSession | null\n isLoading: boolean\n isAuthenticated: boolean\n error: Error | null\n}\n\nexport interface AuthStore extends AuthState {\n setUser: (user: AuthUser | null) => void\n setSession: (session: AuthSession | null) => void\n setLoading: (isLoading: boolean) => void\n setError: (error: Error | null) => void\n reset: () => void\n}\n\nconst initialState: AuthState = {\n user: null,\n session: null,\n isLoading: true,\n isAuthenticated: false,\n error: null,\n}\n\nexport const useAuthStore = create<AuthStore>((set) => ({\n ...initialState,\n\n setUser: (user) =>\n set({ user, isAuthenticated: user !== null }),\n\n setSession: (session) =>\n set({\n session,\n user: session?.user ?? null,\n isAuthenticated: session !== null,\n }),\n\n setLoading: (isLoading) => set({ isLoading }),\n\n setError: (error) => set({ error }),\n\n reset: () => set(initialState),\n}))\n","import React, { createContext, useContext, useEffect, useRef } from 'react'\nimport type { AuthAdapter, AuthProvider as OAuthProvider, AuthSession } from '@fayz-ai/core'\nimport { useAuthStore } from './store'\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\ninterface AuthContextValue {\n signIn: (email: string, password: string) => Promise<AuthSession>\n signUp: (email: string, password: string, fullName: string) => Promise<AuthSession>\n signOut: () => Promise<void>\n signInWithOAuth: (provider: OAuthProvider) => Promise<void>\n resetPassword: (email: string) => Promise<void>\n}\n\nconst AuthContext = createContext<AuthContextValue | null>(null)\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\nexport interface AuthProviderProps {\n adapter: AuthAdapter\n children: React.ReactNode\n}\n\nexport function AuthProvider({ adapter, children }: AuthProviderProps) {\n const { setSession, setLoading, setError, reset } = useAuthStore()\n\n // Keep a stable ref to the adapter so the effect only runs once on mount\n const adapterRef = useRef(adapter)\n adapterRef.current = adapter\n\n useEffect(() => {\n let unsubscribe: (() => void) | undefined\n\n async function init() {\n try {\n setLoading(true)\n const result = await adapterRef.current.getSession()\n setSession(result?.session ?? null)\n } catch (err) {\n setError(err instanceof Error ? err : new Error(String(err)))\n } finally {\n setLoading(false)\n }\n\n // Subscribe to future auth state changes\n unsubscribe = adapterRef.current.onAuthStateChange((user) => {\n if (!user) {\n reset()\n // Keep isLoading false after an explicit sign-out\n setLoading(false)\n }\n // Positive auth state changes are handled via setSession after signIn/signUp\n })\n }\n\n void init()\n\n return () => {\n unsubscribe?.()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n const value: AuthContextValue = {\n async signIn(email, password) {\n setError(null)\n try {\n const session = await adapterRef.current.signIn(email, password)\n setSession(session)\n return session\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async signUp(email, password, fullName) {\n setError(null)\n try {\n const session = await adapterRef.current.signUp(email, password, fullName)\n setSession(session)\n return session\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async signOut() {\n setError(null)\n try {\n await adapterRef.current.signOut()\n reset()\n setLoading(false)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async signInWithOAuth(provider) {\n setError(null)\n try {\n await adapterRef.current.signInWithOAuth(provider)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async resetPassword(email) {\n setError(null)\n try {\n await adapterRef.current.resetPassword(email)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n }\n\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\nexport function useAuth() {\n const ctx = useContext(AuthContext)\n if (!ctx) {\n throw new Error('useAuth must be used inside <AuthProvider>')\n }\n\n const { user, session, isLoading, isAuthenticated, error } = useAuthStore()\n\n return {\n user,\n session,\n isLoading,\n isAuthenticated,\n error,\n signIn: ctx.signIn,\n signUp: ctx.signUp,\n signOut: ctx.signOut,\n signInWithOAuth: ctx.signInWithOAuth,\n resetPassword: ctx.resetPassword,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/adapters/supabase.ts","../src/adapters/mock.ts","../src/store.ts","../src/context.tsx"],"names":[],"mappings":";;;;;;AAWA,SAAS,gBAAgB,YAAA,EAQZ;AACX,EAAA,OAAO;AAAA,IACL,IAAI,YAAA,CAAa,EAAA;AAAA,IACjB,KAAA,EAAO,aAAa,KAAA,IAAS,EAAA;AAAA,IAC7B,QAAA,EACG,aAAa,aAAA,GAAgB,WAAW,KACxC,YAAA,CAAa,aAAA,GAAgB,MAAM,CAAA,IACpC,EAAA;AAAA,IACF,SAAA,EAAW,YAAA,CAAa,aAAA,GAAgB,YAAY;AAAA,GACtD;AACF;AAEA,SAAS,mBAAmB,OAAA,EAMZ;AACd,EAAA,OAAO;AAAA,IACL,aAAa,OAAA,CAAQ,YAAA;AAAA,IACrB,cAAc,OAAA,CAAQ,aAAA;AAAA,IACtB,SAAA,EACE,OAAA,CAAQ,UAAA,IACR,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,GAAA,EAAI,GAAI,GAAI,CAAA,IAAK,OAAA,CAAQ,UAAA,IAAc,IAAA,CAAA;AAAA,IACzD,IAAA,EAAM,eAAA,CAAgB,OAAA,CAAQ,IAAI;AAAA,GACpC;AACF;AAEO,SAAS,0BAA0B,MAAA,EAAyC;AACjF,EAAA,MAAM,WAAW,MAAA,CAAO,cAAA,IAAkB,aAAa,MAAA,CAAO,WAAA,EAAa,OAAO,eAAe,CAAA;AAEjG,EAAA,OAAO;AAAA,IACL,MAAM,UAAA,GAAa;AACjB,MAAA,MAAM;AAAA,QACJ,IAAA,EAAM,EAAE,OAAA;AAAQ,OAClB,GAAI,MAAM,QAAA,CAAS,IAAA,CAAK,UAAA,EAAW;AACnC,MAAA,IAAI,CAAC,SAAS,OAAO,IAAA;AACrB,MAAA,MAAM,MAAA,GAAS,mBAAmB,OAAO,CAAA;AACzC,MAAA,OAAO,EAAE,IAAA,EAAM,MAAA,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AA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,OAAA;AAAA,IACA,SAAA;AAAA,IACA,eAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAQ,GAAA,CAAI,MAAA;AAAA,IACZ,QAAQ,GAAA,CAAI,MAAA;AAAA,IACZ,SAAS,GAAA,CAAI,OAAA;AAAA,IACb,iBAAiB,GAAA,CAAI,eAAA;AAAA,IACrB,eAAe,GAAA,CAAI,aAAA;AAAA,IACnB,gBAAgB,GAAA,CAAI,cAAA;AAAA,IACpB,gBAAgB,GAAA,CAAI,cAAA;AAAA,IACpB,YAAY,GAAA,CAAI;AAAA,GAClB;AACF","file":"index.js","sourcesContent":["import { createClient, type SupabaseClient } from '@supabase/supabase-js'\nimport type { AuthAdapter, AuthUser, AuthSession, AuthProvider } from '@fayz-ai/core'\n\nexport interface SupabaseAuthConfig {\n supabaseUrl: string\n supabaseAnonKey: string\n supabaseClient?: SupabaseClient\n callbackUrl?: string\n resetPasswordUrl?: string\n}\n\nfunction mapSupabaseUser(supabaseUser: {\n id: string\n email?: string | null\n created_at?: string\n updated_at?: string | null\n email_confirmed_at?: string | null\n user_metadata?: Record<string, unknown>\n app_metadata?: { providers?: string[]; provider?: string }\n}): AuthUser {\n return {\n id: supabaseUser.id,\n email: supabaseUser.email ?? '',\n fullName:\n (supabaseUser.user_metadata?.['full_name'] as string | undefined) ??\n (supabaseUser.user_metadata?.['name'] as string | undefined) ??\n '',\n avatarUrl: supabaseUser.user_metadata?.['avatar_url'] as string | undefined,\n }\n}\n\nfunction mapSupabaseSession(session: {\n access_token: string\n refresh_token?: string\n expires_at?: number\n expires_in?: number\n user: Parameters<typeof mapSupabaseUser>[0]\n}): AuthSession {\n return {\n accessToken: session.access_token,\n refreshToken: session.refresh_token,\n expiresAt:\n session.expires_at ??\n Math.floor(Date.now() / 1000) + (session.expires_in ?? 3600),\n user: mapSupabaseUser(session.user),\n }\n}\n\nexport function createSupabaseAuthAdapter(config: SupabaseAuthConfig): AuthAdapter {\n const supabase = config.supabaseClient ?? createClient(config.supabaseUrl, config.supabaseAnonKey)\n\n return {\n async getSession() {\n const {\n data: { session },\n } = await supabase.auth.getSession()\n if (!session) return null\n const mapped = mapSupabaseSession(session)\n return { user: mapped.user, session: mapped }\n },\n\n onAuthStateChange(cb) {\n const {\n data: { subscription },\n } = supabase.auth.onAuthStateChange((_event, session) => {\n cb(session ? mapSupabaseUser(session.user) : null)\n })\n return () => subscription.unsubscribe()\n },\n\n async signIn(email, password) {\n const { data, error } = await supabase.auth.signInWithPassword({ email, password })\n if (error) throw error\n return mapSupabaseSession(data.session)\n },\n\n async signUp(email, password, fullName) {\n const { data, error } = await supabase.auth.signUp({\n email,\n password,\n options: { data: { full_name: fullName } },\n })\n if (error) throw error\n\n // When email confirmation is required, session is null\n if (!data.session) {\n if (!data.user) throw new Error('Signup failed: no user returned')\n return {\n accessToken: '',\n refreshToken: '',\n expiresAt: 0,\n user: mapSupabaseUser(data.user),\n }\n }\n\n return mapSupabaseSession(data.session)\n },\n\n async signOut() {\n const { error } = await supabase.auth.signOut()\n if (error) throw error\n },\n\n async signInWithOAuth(provider: AuthProvider) {\n const { error } = await supabase.auth.signInWithOAuth({\n provider: provider as 'google' | 'github' | 'apple',\n options: {\n redirectTo:\n config.callbackUrl ??\n (typeof window !== 'undefined' ? `${window.location.origin}/auth/callback` : undefined),\n },\n })\n if (error) throw error\n },\n\n async resetPassword(email, options) {\n const { error } = await supabase.auth.resetPasswordForEmail(email, {\n redirectTo:\n options?.redirectTo ??\n config.resetPasswordUrl ??\n (typeof window !== 'undefined' ? `${window.location.origin}/auth/reset-password` : undefined),\n })\n if (error) throw error\n },\n\n async updatePassword(password) {\n const { data, error } = await supabase.auth.updateUser({ password })\n if (error) throw error\n const {\n data: { session },\n } = await supabase.auth.getSession()\n if (session) return mapSupabaseSession(session)\n if (!data.user) return undefined\n return {\n accessToken: '',\n refreshToken: '',\n expiresAt: 0,\n user: mapSupabaseUser(data.user),\n }\n },\n\n async handleCallback(url) {\n const target = url ?? (typeof window !== 'undefined' ? window.location.href : '')\n const code = new URL(target).searchParams.get('code')\n if (code) {\n const { data, error } = await supabase.auth.exchangeCodeForSession(code)\n if (error) throw error\n return data.session ? mapSupabaseSession(data.session) : null\n }\n const {\n data: { session },\n } = await supabase.auth.getSession()\n return session ? mapSupabaseSession(session) : null\n },\n\n async inviteUser(email, options) {\n // Native, edge-function-free invite: a passwordless magic link. Sends the\n // e-mail + creates the auth user (anon-callable, no service-role/admin).\n // Membership is NOT granted from `data` (a client could forge it) — the\n // accept-time trigger trusts the RLS-protected saas_core.invitations row.\n const { error } = await supabase.auth.signInWithOtp({\n email,\n options: {\n shouldCreateUser: true,\n emailRedirectTo:\n options?.redirectTo ??\n (typeof window !== 'undefined' ? `${window.location.origin}/` : undefined),\n data: options?.data,\n },\n })\n if (error) throw error\n },\n }\n}\n","import type { AuthAdapter, AuthUser, AuthSession } from '@fayz-ai/core'\n\nexport interface MockUser {\n id: string\n email: string\n fullName: string\n role?: string\n}\n\nconst DEFAULT_MOCK_USER: MockUser = {\n id: 'mock-user-id',\n email: 'demo@fayz.dev',\n fullName: 'Demo User',\n role: 'admin',\n}\n\nconst STORAGE_KEY = 'fayz:mock-auth'\n\nfunction toAuthUser(mockUser: MockUser): AuthUser {\n return {\n id: mockUser.id,\n email: mockUser.email,\n fullName: mockUser.fullName,\n }\n}\n\nfunction createMockSession(user: AuthUser): AuthSession {\n return {\n accessToken: `mock-token-${user.id}`,\n refreshToken: `mock-refresh-${user.id}`,\n expiresAt: Math.floor(Date.now() / 1000) + 3600,\n user,\n }\n}\n\nfunction getStored(): { user: AuthUser; session: AuthSession } | null {\n try {\n if (typeof localStorage === 'undefined') return null\n const raw = localStorage.getItem(STORAGE_KEY)\n if (!raw) return null\n return JSON.parse(raw) as { user: AuthUser; session: AuthSession }\n } catch {\n return null\n }\n}\n\nfunction setStored(data: { user: AuthUser; session: AuthSession } | null): void {\n try {\n if (typeof localStorage === 'undefined') return\n if (data) {\n localStorage.setItem(STORAGE_KEY, JSON.stringify(data))\n } else {\n localStorage.removeItem(STORAGE_KEY)\n }\n } catch {\n // SSR or storage unavailable — silently skip\n }\n}\n\nexport function createMockAuthAdapter(mockUser: MockUser = DEFAULT_MOCK_USER): AuthAdapter {\n const listeners = new Set<(user: AuthUser | null) => void>()\n\n function notifyListeners(user: AuthUser | null): void {\n for (const cb of listeners) cb(user)\n }\n\n return {\n async getSession() {\n return getStored()\n },\n\n onAuthStateChange(cb) {\n listeners.add(cb)\n return () => {\n listeners.delete(cb)\n }\n },\n\n async signIn(email, _password) {\n // Mock accepts any credentials, but the identity FOLLOWS the email —\n // storefront customers and saas users keep their own purchase/session\n // history instead of all becoming the configured demo user.\n const stored = getStored()\n const user: AuthUser =\n stored && stored.user.email === email\n ? stored.user\n : {\n id: email === mockUser.email ? mockUser.id : `mock-${email}`,\n email,\n fullName: email === mockUser.email ? mockUser.fullName : (email.split('@')[0] ?? 'Cliente'),\n }\n const session = createMockSession(user)\n setStored({ user, session })\n notifyListeners(user)\n return session\n },\n\n async signUp(email, _password, fullName) {\n // Mock signup creates a user from the provided details\n const user: AuthUser = {\n id: `mock-${email}`,\n email,\n fullName: fullName || (email.split('@')[0] ?? 'Cliente'),\n }\n const session = createMockSession(user)\n setStored({ user, session })\n notifyListeners(user)\n return session\n },\n\n async signOut() {\n setStored(null)\n notifyListeners(null)\n },\n\n async signInWithOAuth(_provider) {\n // Mock OAuth signs in as the configured user\n const user = toAuthUser(mockUser)\n const session = createMockSession(user)\n setStored({ user, session })\n notifyListeners(user)\n },\n\n async resetPassword(_email) {\n // No-op in mock\n },\n\n async updatePassword(_password) {\n const stored = getStored()\n return stored?.session\n },\n\n async handleCallback() {\n return getStored()?.session ?? null\n },\n\n async inviteUser(_email, _options) {\n // No admin path in mock — the org mock adapter still records the pending\n // invite so the Team UI shows it. Delivery is a no-op locally.\n },\n }\n}\n","import { create } from 'zustand'\nimport type { AuthUser, AuthSession } from '@fayz-ai/core'\n\nexport interface AuthState {\n user: AuthUser | null\n session: AuthSession | null\n isLoading: boolean\n isAuthenticated: boolean\n error: Error | null\n}\n\nexport interface AuthStore extends AuthState {\n setUser: (user: AuthUser | null) => void\n setSession: (session: AuthSession | null) => void\n setLoading: (isLoading: boolean) => void\n setError: (error: Error | null) => void\n reset: () => void\n}\n\nconst initialState: AuthState = {\n user: null,\n session: null,\n isLoading: true,\n isAuthenticated: false,\n error: null,\n}\n\nexport const useAuthStore = create<AuthStore>((set) => ({\n ...initialState,\n\n setUser: (user) =>\n set({ user, isAuthenticated: user !== null }),\n\n setSession: (session) =>\n set({\n session,\n user: session?.user ?? null,\n isAuthenticated: session !== null,\n }),\n\n setLoading: (isLoading) => set({ isLoading }),\n\n setError: (error) => set({ error }),\n\n reset: () => set(initialState),\n}))\n","import React, { createContext, useContext, useEffect, useRef } from 'react'\nimport type { AuthAdapter, AuthProvider as OAuthProvider, AuthSession } from '@fayz-ai/core'\nimport { useAuthStore } from './store'\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\ninterface AuthContextValue {\n signIn: (email: string, password: string) => Promise<AuthSession>\n signUp: (email: string, password: string, fullName: string) => Promise<AuthSession>\n signOut: () => Promise<void>\n signInWithOAuth: (provider: OAuthProvider) => Promise<void>\n resetPassword: (email: string, options?: { redirectTo?: string }) => Promise<void>\n updatePassword: (password: string) => Promise<AuthSession | void>\n handleCallback: (url?: string) => Promise<AuthSession | null>\n inviteUser: (email: string, options?: { redirectTo?: string; data?: Record<string, unknown> }) => Promise<void>\n}\n\nconst AuthContext = createContext<AuthContextValue | null>(null)\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\nexport interface AuthProviderProps {\n adapter: AuthAdapter\n children: React.ReactNode\n}\n\nexport function AuthProvider({ adapter, children }: AuthProviderProps) {\n const { setSession, setLoading, setError, reset } = useAuthStore()\n\n // Keep a stable ref to the adapter so the effect only runs once on mount\n const adapterRef = useRef(adapter)\n adapterRef.current = adapter\n\n useEffect(() => {\n let unsubscribe: (() => void) | undefined\n\n async function init() {\n try {\n setLoading(true)\n const result = await adapterRef.current.getSession()\n setSession(result?.session ?? null)\n } catch (err) {\n setError(err instanceof Error ? err : new Error(String(err)))\n } finally {\n setLoading(false)\n }\n\n // Subscribe to future auth state changes\n unsubscribe = adapterRef.current.onAuthStateChange((user) => {\n if (!user) {\n reset()\n // Keep isLoading false after an explicit sign-out\n setLoading(false)\n }\n // Positive auth state changes are handled via setSession after signIn/signUp\n })\n }\n\n void init()\n\n return () => {\n unsubscribe?.()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n const value: AuthContextValue = {\n async signIn(email, password) {\n setError(null)\n try {\n const session = await adapterRef.current.signIn(email, password)\n setSession(session)\n return session\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async signUp(email, password, fullName) {\n setError(null)\n try {\n const session = await adapterRef.current.signUp(email, password, fullName)\n setSession(session)\n return session\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async signOut() {\n setError(null)\n try {\n await adapterRef.current.signOut()\n reset()\n setLoading(false)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async signInWithOAuth(provider) {\n setError(null)\n try {\n await adapterRef.current.signInWithOAuth(provider)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async resetPassword(email, options) {\n setError(null)\n try {\n await adapterRef.current.resetPassword(email, options)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async updatePassword(password) {\n setError(null)\n try {\n const session = await adapterRef.current.updatePassword?.(password)\n if (session) setSession(session)\n return session\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async handleCallback(url) {\n setError(null)\n try {\n const session = await adapterRef.current.handleCallback?.(url) ?? null\n if (session) setSession(session)\n return session\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n\n async inviteUser(email, options) {\n setError(null)\n try {\n await adapterRef.current.inviteUser?.(email, options)\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n throw error\n }\n },\n }\n\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\nexport function useAuth() {\n const ctx = useContext(AuthContext)\n if (!ctx) {\n throw new Error('useAuth must be used inside <AuthProvider>')\n }\n\n const { user, session, isLoading, isAuthenticated, error } = useAuthStore()\n\n return {\n user,\n session,\n isLoading,\n isAuthenticated,\n error,\n signIn: ctx.signIn,\n signUp: ctx.signUp,\n signOut: ctx.signOut,\n signInWithOAuth: ctx.signInWithOAuth,\n resetPassword: ctx.resetPassword,\n updatePassword: ctx.updatePassword,\n handleCallback: ctx.handleCallback,\n inviteUser: ctx.inviteUser,\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fayz-ai/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "Fayz SDK auth — pluggable authentication adapters with React hooks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@supabase/supabase-js": "^2.45.0",
|
|
26
26
|
"zustand": "^4.5.0",
|
|
27
|
-
"@fayz-ai/core": "^0.
|
|
27
|
+
"@fayz-ai/core": "^0.6.6"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/react": "^18.3.0",
|
|
@@ -33,9 +33,6 @@
|
|
|
33
33
|
"typescript": "^5.5.0"
|
|
34
34
|
},
|
|
35
35
|
"license": "MIT",
|
|
36
|
-
"publishConfig": {
|
|
37
|
-
"access": "public"
|
|
38
|
-
},
|
|
39
36
|
"scripts": {
|
|
40
37
|
"build": "tsup && tsc --emitDeclarationOnly --declaration --declarationMap --noEmit false",
|
|
41
38
|
"dev": "tsup --watch",
|
package/src/adapters/mock.ts
CHANGED
|
@@ -124,5 +124,19 @@ export function createMockAuthAdapter(mockUser: MockUser = DEFAULT_MOCK_USER): A
|
|
|
124
124
|
async resetPassword(_email) {
|
|
125
125
|
// No-op in mock
|
|
126
126
|
},
|
|
127
|
+
|
|
128
|
+
async updatePassword(_password) {
|
|
129
|
+
const stored = getStored()
|
|
130
|
+
return stored?.session
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
async handleCallback() {
|
|
134
|
+
return getStored()?.session ?? null
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
async inviteUser(_email, _options) {
|
|
138
|
+
// No admin path in mock — the org mock adapter still records the pending
|
|
139
|
+
// invite so the Team UI shows it. Delivery is a no-op locally.
|
|
140
|
+
},
|
|
127
141
|
}
|
|
128
142
|
}
|
package/src/adapters/supabase.ts
CHANGED
|
@@ -5,6 +5,8 @@ export interface SupabaseAuthConfig {
|
|
|
5
5
|
supabaseUrl: string
|
|
6
6
|
supabaseAnonKey: string
|
|
7
7
|
supabaseClient?: SupabaseClient
|
|
8
|
+
callbackUrl?: string
|
|
9
|
+
resetPasswordUrl?: string
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
function mapSupabaseUser(supabaseUser: {
|
|
@@ -104,20 +106,67 @@ export function createSupabaseAuthAdapter(config: SupabaseAuthConfig): AuthAdapt
|
|
|
104
106
|
provider: provider as 'google' | 'github' | 'apple',
|
|
105
107
|
options: {
|
|
106
108
|
redirectTo:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
: undefined,
|
|
109
|
+
config.callbackUrl ??
|
|
110
|
+
(typeof window !== 'undefined' ? `${window.location.origin}/auth/callback` : undefined),
|
|
110
111
|
},
|
|
111
112
|
})
|
|
112
113
|
if (error) throw error
|
|
113
114
|
},
|
|
114
115
|
|
|
115
|
-
async resetPassword(email) {
|
|
116
|
+
async resetPassword(email, options) {
|
|
116
117
|
const { error } = await supabase.auth.resetPasswordForEmail(email, {
|
|
117
118
|
redirectTo:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
options?.redirectTo ??
|
|
120
|
+
config.resetPasswordUrl ??
|
|
121
|
+
(typeof window !== 'undefined' ? `${window.location.origin}/auth/reset-password` : undefined),
|
|
122
|
+
})
|
|
123
|
+
if (error) throw error
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
async updatePassword(password) {
|
|
127
|
+
const { data, error } = await supabase.auth.updateUser({ password })
|
|
128
|
+
if (error) throw error
|
|
129
|
+
const {
|
|
130
|
+
data: { session },
|
|
131
|
+
} = await supabase.auth.getSession()
|
|
132
|
+
if (session) return mapSupabaseSession(session)
|
|
133
|
+
if (!data.user) return undefined
|
|
134
|
+
return {
|
|
135
|
+
accessToken: '',
|
|
136
|
+
refreshToken: '',
|
|
137
|
+
expiresAt: 0,
|
|
138
|
+
user: mapSupabaseUser(data.user),
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
async handleCallback(url) {
|
|
143
|
+
const target = url ?? (typeof window !== 'undefined' ? window.location.href : '')
|
|
144
|
+
const code = new URL(target).searchParams.get('code')
|
|
145
|
+
if (code) {
|
|
146
|
+
const { data, error } = await supabase.auth.exchangeCodeForSession(code)
|
|
147
|
+
if (error) throw error
|
|
148
|
+
return data.session ? mapSupabaseSession(data.session) : null
|
|
149
|
+
}
|
|
150
|
+
const {
|
|
151
|
+
data: { session },
|
|
152
|
+
} = await supabase.auth.getSession()
|
|
153
|
+
return session ? mapSupabaseSession(session) : null
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
async inviteUser(email, options) {
|
|
157
|
+
// Native, edge-function-free invite: a passwordless magic link. Sends the
|
|
158
|
+
// e-mail + creates the auth user (anon-callable, no service-role/admin).
|
|
159
|
+
// Membership is NOT granted from `data` (a client could forge it) — the
|
|
160
|
+
// accept-time trigger trusts the RLS-protected saas_core.invitations row.
|
|
161
|
+
const { error } = await supabase.auth.signInWithOtp({
|
|
162
|
+
email,
|
|
163
|
+
options: {
|
|
164
|
+
shouldCreateUser: true,
|
|
165
|
+
emailRedirectTo:
|
|
166
|
+
options?.redirectTo ??
|
|
167
|
+
(typeof window !== 'undefined' ? `${window.location.origin}/` : undefined),
|
|
168
|
+
data: options?.data,
|
|
169
|
+
},
|
|
121
170
|
})
|
|
122
171
|
if (error) throw error
|
|
123
172
|
},
|
package/src/context.tsx
CHANGED
|
@@ -11,7 +11,10 @@ interface AuthContextValue {
|
|
|
11
11
|
signUp: (email: string, password: string, fullName: string) => Promise<AuthSession>
|
|
12
12
|
signOut: () => Promise<void>
|
|
13
13
|
signInWithOAuth: (provider: OAuthProvider) => Promise<void>
|
|
14
|
-
resetPassword: (email: string) => Promise<void>
|
|
14
|
+
resetPassword: (email: string, options?: { redirectTo?: string }) => Promise<void>
|
|
15
|
+
updatePassword: (password: string) => Promise<AuthSession | void>
|
|
16
|
+
handleCallback: (url?: string) => Promise<AuthSession | null>
|
|
17
|
+
inviteUser: (email: string, options?: { redirectTo?: string; data?: Record<string, unknown> }) => Promise<void>
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
const AuthContext = createContext<AuthContextValue | null>(null)
|
|
@@ -116,10 +119,47 @@ export function AuthProvider({ adapter, children }: AuthProviderProps) {
|
|
|
116
119
|
}
|
|
117
120
|
},
|
|
118
121
|
|
|
119
|
-
async resetPassword(email) {
|
|
122
|
+
async resetPassword(email, options) {
|
|
120
123
|
setError(null)
|
|
121
124
|
try {
|
|
122
|
-
await adapterRef.current.resetPassword(email)
|
|
125
|
+
await adapterRef.current.resetPassword(email, options)
|
|
126
|
+
} catch (err) {
|
|
127
|
+
const error = err instanceof Error ? err : new Error(String(err))
|
|
128
|
+
setError(error)
|
|
129
|
+
throw error
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
async updatePassword(password) {
|
|
134
|
+
setError(null)
|
|
135
|
+
try {
|
|
136
|
+
const session = await adapterRef.current.updatePassword?.(password)
|
|
137
|
+
if (session) setSession(session)
|
|
138
|
+
return session
|
|
139
|
+
} catch (err) {
|
|
140
|
+
const error = err instanceof Error ? err : new Error(String(err))
|
|
141
|
+
setError(error)
|
|
142
|
+
throw error
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
async handleCallback(url) {
|
|
147
|
+
setError(null)
|
|
148
|
+
try {
|
|
149
|
+
const session = await adapterRef.current.handleCallback?.(url) ?? null
|
|
150
|
+
if (session) setSession(session)
|
|
151
|
+
return session
|
|
152
|
+
} catch (err) {
|
|
153
|
+
const error = err instanceof Error ? err : new Error(String(err))
|
|
154
|
+
setError(error)
|
|
155
|
+
throw error
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
async inviteUser(email, options) {
|
|
160
|
+
setError(null)
|
|
161
|
+
try {
|
|
162
|
+
await adapterRef.current.inviteUser?.(email, options)
|
|
123
163
|
} catch (err) {
|
|
124
164
|
const error = err instanceof Error ? err : new Error(String(err))
|
|
125
165
|
setError(error)
|
|
@@ -154,5 +194,8 @@ export function useAuth() {
|
|
|
154
194
|
signOut: ctx.signOut,
|
|
155
195
|
signInWithOAuth: ctx.signInWithOAuth,
|
|
156
196
|
resetPassword: ctx.resetPassword,
|
|
197
|
+
updatePassword: ctx.updatePassword,
|
|
198
|
+
handleCallback: ctx.handleCallback,
|
|
199
|
+
inviteUser: ctx.inviteUser,
|
|
157
200
|
}
|
|
158
201
|
}
|