@bouko/react 2.9.3 → 2.9.4
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/hooks/auth/context.d.ts +9 -0
- package/dist/hooks/auth/context.js +9 -0
- package/dist/hooks/auth/index.d.ts +2 -0
- package/dist/hooks/auth/index.js +2 -0
- package/dist/hooks/auth/provider.d.ts +5 -0
- package/dist/hooks/auth/provider.js +25 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Session, User } from "@supabase/supabase-js";
|
|
2
|
+
type AuthState = {
|
|
3
|
+
session: Session | null;
|
|
4
|
+
user: User | null;
|
|
5
|
+
loading: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const Context: import("react").Context<AuthState>;
|
|
8
|
+
export declare function useAuth(): AuthState;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useMemo } from "react";
|
|
3
|
+
import { Context } from "./context";
|
|
4
|
+
export function AuthProvider({ supabase, children }) {
|
|
5
|
+
const [session, setSession] = useState(null);
|
|
6
|
+
const [loading, setLoading] = useState(true);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
let mounted = true;
|
|
9
|
+
supabase.auth.getSession().then(({ data }) => {
|
|
10
|
+
if (!mounted)
|
|
11
|
+
return;
|
|
12
|
+
setSession(data.session ?? null);
|
|
13
|
+
setLoading(false);
|
|
14
|
+
});
|
|
15
|
+
const { data: sub } = supabase.auth.onAuthStateChange((_event, newSession) => {
|
|
16
|
+
setSession(newSession);
|
|
17
|
+
});
|
|
18
|
+
return () => {
|
|
19
|
+
mounted = false;
|
|
20
|
+
sub.subscription.unsubscribe();
|
|
21
|
+
};
|
|
22
|
+
}, []);
|
|
23
|
+
const value = useMemo(() => ({ session, user: session?.user ?? null, loading }), [session, loading]);
|
|
24
|
+
return (_jsx(Context.Provider, { value: value, children: children }));
|
|
25
|
+
}
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
|
|
3
3
|
"name": "@bouko/react",
|
|
4
|
-
"version": "2.9.
|
|
4
|
+
"version": "2.9.4",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"@bouko/style": "^0.1.7",
|
|
27
27
|
"@bouko/time": "^0.1.3",
|
|
28
28
|
"@bouko/ts": "^0.3.5",
|
|
29
|
+
"@supabase/supabase-js": "^2.90.1",
|
|
29
30
|
"@wavesurfer/react": "^1.0.11",
|
|
30
31
|
"clsx": "^2.1.1",
|
|
31
32
|
"file-type": "^21.0.0",
|