@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.
@@ -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,9 @@
1
+ import { createContext, useContext } from "react";
2
+ export const Context = createContext({
3
+ session: null,
4
+ user: null,
5
+ loading: true
6
+ });
7
+ export function useAuth() {
8
+ return useContext(Context);
9
+ }
@@ -0,0 +1,2 @@
1
+ export { AuthProvider } from "./provider";
2
+ export { useAuth } from "./context";
@@ -0,0 +1,2 @@
1
+ export { AuthProvider } from "./provider";
2
+ export { useAuth } from "./context";
@@ -0,0 +1,5 @@
1
+ import { SupabaseClient } from "@supabase/supabase-js";
2
+ export declare function AuthProvider({ supabase, children }: {
3
+ supabase: SupabaseClient;
4
+ children: React.ReactNode;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -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
+ }
@@ -5,3 +5,4 @@ export { default as useInterval } from "./clock/interval";
5
5
  export { default as useSound } from "./audio/sound";
6
6
  export { withAudio, type DivRef, type AudioRef } from "./element/with-audio";
7
7
  export * from "./router/params";
8
+ export * from "./auth";
@@ -5,3 +5,4 @@ export { default as useInterval } from "./clock/interval";
5
5
  export { default as useSound } from "./audio/sound";
6
6
  export { withAudio } from "./element/with-audio";
7
7
  export * from "./router/params";
8
+ export * from "./auth";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/react",
4
- "version": "2.9.3",
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",