@bouko/react 2.9.3 → 2.9.5
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/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/route/index.d.ts +7 -0
- package/dist/components/route/index.js +11 -0
- 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 +5 -1
|
@@ -6,6 +6,7 @@ export { default as Heading } from "./heading/normal";
|
|
|
6
6
|
export { default as PageHeading } from "./heading/page";
|
|
7
7
|
export * from "./layout/flex";
|
|
8
8
|
export * from "./tab";
|
|
9
|
+
export * from "./route";
|
|
9
10
|
export { default as Pagination } from "./pagination";
|
|
10
11
|
export { default as Button } from "./button/normal";
|
|
11
12
|
export { default as IconButton } from "./button/icon";
|
package/dist/components/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { default as Heading } from "./heading/normal";
|
|
|
6
6
|
export { default as PageHeading } from "./heading/page";
|
|
7
7
|
export * from "./layout/flex";
|
|
8
8
|
export * from "./tab";
|
|
9
|
+
export * from "./route";
|
|
9
10
|
export { default as Pagination } from "./pagination";
|
|
10
11
|
export { default as Button } from "./button/normal";
|
|
11
12
|
export { default as IconButton } from "./button/icon";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useLocation, Navigate } from "react-router-dom";
|
|
3
|
+
export function ProtectedRoute({ loading, authed, children }) {
|
|
4
|
+
const location = useLocation();
|
|
5
|
+
if (loading)
|
|
6
|
+
return null;
|
|
7
|
+
if (!authed)
|
|
8
|
+
return;
|
|
9
|
+
_jsx(Navigate, { to: "/", state: { from: location }, replace: true });
|
|
10
|
+
return children;
|
|
11
|
+
}
|
|
@@ -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.5",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
},
|
|
14
14
|
"author": "",
|
|
15
15
|
"description": "",
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"react-router-dom": "^7.12.0"
|
|
18
|
+
},
|
|
16
19
|
"engines": {},
|
|
17
20
|
|
|
18
21
|
"scripts": {
|
|
@@ -26,6 +29,7 @@
|
|
|
26
29
|
"@bouko/style": "^0.1.7",
|
|
27
30
|
"@bouko/time": "^0.1.3",
|
|
28
31
|
"@bouko/ts": "^0.3.5",
|
|
32
|
+
"@supabase/supabase-js": "^2.90.1",
|
|
29
33
|
"@wavesurfer/react": "^1.0.11",
|
|
30
34
|
"clsx": "^2.1.1",
|
|
31
35
|
"file-type": "^21.0.0",
|