@aurabase/aurabase-js 0.5.2 → 0.5.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/{AuraClient-DL7mqfNu.d.cts → AuraClient-5jDiXjrO.d.cts} +27 -3
- package/dist/{AuraClient-DL7mqfNu.d.ts → AuraClient-5jDiXjrO.d.ts} +27 -3
- package/dist/index.cjs +26 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +26 -1
- package/dist/nextjs.cjs +389 -0
- package/dist/nextjs.d.cts +126 -0
- package/dist/nextjs.d.ts +126 -0
- package/dist/nextjs.js +383 -0
- package/dist/react.cjs +150 -0
- package/dist/react.d.cts +82 -0
- package/dist/react.d.ts +82 -0
- package/dist/react.js +143 -0
- package/dist/ssr.cjs +26 -1
- package/dist/ssr.d.cts +1 -1
- package/dist/ssr.d.ts +1 -1
- package/dist/ssr.js +26 -1
- package/package.json +29 -9
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// src/react.ts
|
|
11
|
+
function getReact() {
|
|
12
|
+
const g = globalThis;
|
|
13
|
+
if (g.React) {
|
|
14
|
+
return g.React;
|
|
15
|
+
}
|
|
16
|
+
if (typeof __require === "function") {
|
|
17
|
+
try {
|
|
18
|
+
return __require("react");
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
var defaultAuthContextValue = {
|
|
26
|
+
client: null,
|
|
27
|
+
user: null,
|
|
28
|
+
session: null,
|
|
29
|
+
accessToken: null,
|
|
30
|
+
isLoading: true,
|
|
31
|
+
isAuthenticated: false,
|
|
32
|
+
signOut: async () => {
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var authContextInstance = null;
|
|
36
|
+
function getAuthContext() {
|
|
37
|
+
if (!authContextInstance) {
|
|
38
|
+
const React = getReact();
|
|
39
|
+
if (React?.createContext) {
|
|
40
|
+
authContextInstance = React.createContext(defaultAuthContextValue);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return authContextInstance;
|
|
44
|
+
}
|
|
45
|
+
function AuthProvider({ client, children, initialSession = null }) {
|
|
46
|
+
const React = getReact();
|
|
47
|
+
if (!React) {
|
|
48
|
+
throw new Error("[@aurabase/react] React est requis pour utiliser <AuthProvider>.");
|
|
49
|
+
}
|
|
50
|
+
const [session, setSession] = React.useState(initialSession);
|
|
51
|
+
const [user, setUser] = React.useState(initialSession?.user ?? null);
|
|
52
|
+
const [isLoading, setIsLoading] = React.useState(!initialSession);
|
|
53
|
+
React.useEffect(() => {
|
|
54
|
+
let isMounted = true;
|
|
55
|
+
void client.auth.getSession().then(({ data }) => {
|
|
56
|
+
if (!isMounted) return;
|
|
57
|
+
const s = data?.session ?? null;
|
|
58
|
+
setSession(s);
|
|
59
|
+
setUser(s?.user ?? null);
|
|
60
|
+
setIsLoading(false);
|
|
61
|
+
}).catch(() => {
|
|
62
|
+
if (!isMounted) return;
|
|
63
|
+
setIsLoading(false);
|
|
64
|
+
});
|
|
65
|
+
const subscription = client.auth.onAuthStateChange(({ event, user: nextUser }) => {
|
|
66
|
+
if (!isMounted) return;
|
|
67
|
+
if (event === "SIGNED_OUT") {
|
|
68
|
+
setSession(null);
|
|
69
|
+
setUser(null);
|
|
70
|
+
} else if (event === "SIGNED_IN" || event === "TOKEN_REFRESHED" || event === "USER_UPDATED") {
|
|
71
|
+
void client.auth.getSession().then(({ data }) => {
|
|
72
|
+
if (!isMounted) return;
|
|
73
|
+
const s = data?.session ?? null;
|
|
74
|
+
setSession(s);
|
|
75
|
+
setUser(nextUser ?? s?.user ?? null);
|
|
76
|
+
}).catch(() => {
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return () => {
|
|
81
|
+
isMounted = false;
|
|
82
|
+
subscription.unsubscribe();
|
|
83
|
+
};
|
|
84
|
+
}, [client]);
|
|
85
|
+
const value = React.useMemo(
|
|
86
|
+
() => ({
|
|
87
|
+
client,
|
|
88
|
+
user,
|
|
89
|
+
session,
|
|
90
|
+
accessToken: session?.access_token ?? null,
|
|
91
|
+
isLoading,
|
|
92
|
+
isAuthenticated: !!user,
|
|
93
|
+
signOut: async () => {
|
|
94
|
+
await client.auth.signOut();
|
|
95
|
+
setSession(null);
|
|
96
|
+
setUser(null);
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
[client, user, session, isLoading]
|
|
100
|
+
);
|
|
101
|
+
const Context = getAuthContext();
|
|
102
|
+
if (!Context) {
|
|
103
|
+
return children;
|
|
104
|
+
}
|
|
105
|
+
return React.createElement(Context.Provider, { value }, children);
|
|
106
|
+
}
|
|
107
|
+
function useAuth() {
|
|
108
|
+
const React = getReact();
|
|
109
|
+
const Context = getAuthContext();
|
|
110
|
+
if (!React || !Context) {
|
|
111
|
+
return {
|
|
112
|
+
client: null,
|
|
113
|
+
user: null,
|
|
114
|
+
session: null,
|
|
115
|
+
accessToken: null,
|
|
116
|
+
isLoading: false,
|
|
117
|
+
isAuthenticated: false,
|
|
118
|
+
signOut: async () => {
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return React.useContext(Context);
|
|
123
|
+
}
|
|
124
|
+
function useUser() {
|
|
125
|
+
const { user } = useAuth();
|
|
126
|
+
return user;
|
|
127
|
+
}
|
|
128
|
+
function useSession() {
|
|
129
|
+
const { session } = useAuth();
|
|
130
|
+
return session;
|
|
131
|
+
}
|
|
132
|
+
function SignedIn({ children }) {
|
|
133
|
+
const React = getReact();
|
|
134
|
+
const { isAuthenticated, isLoading } = useAuth();
|
|
135
|
+
if (isLoading || !isAuthenticated || !React) return null;
|
|
136
|
+
return React.createElement(React.Fragment, null, children);
|
|
137
|
+
}
|
|
138
|
+
function SignedOut({ children }) {
|
|
139
|
+
const React = getReact();
|
|
140
|
+
const { isAuthenticated, isLoading } = useAuth();
|
|
141
|
+
if (isLoading || isAuthenticated || !React) return null;
|
|
142
|
+
return React.createElement(React.Fragment, null, children);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
exports.AuthProvider = AuthProvider;
|
|
146
|
+
exports.SignedIn = SignedIn;
|
|
147
|
+
exports.SignedOut = SignedOut;
|
|
148
|
+
exports.useAuth = useAuth;
|
|
149
|
+
exports.useSession = useSession;
|
|
150
|
+
exports.useUser = useUser;
|
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { User, Session } from '@aurabase/core';
|
|
2
|
+
import { A as AuraClient } from './AuraClient-5jDiXjrO.cjs';
|
|
3
|
+
import '@aurabase/ai';
|
|
4
|
+
import '@aurabase/auth';
|
|
5
|
+
import '@aurabase/db';
|
|
6
|
+
import '@aurabase/functions';
|
|
7
|
+
import '@aurabase/notifications';
|
|
8
|
+
import '@aurabase/realtime';
|
|
9
|
+
import '@aurabase/storage';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* React Context, hooks, and lifecycle primitives for Aurabase Auth.
|
|
13
|
+
*
|
|
14
|
+
* Provides Clerk-level reactive DX:
|
|
15
|
+
* - `<AuthProvider>`: React context managing real-time auth state across the tree.
|
|
16
|
+
* - `useAuth()`: Access client, status, token, and sign-out helpers.
|
|
17
|
+
* - `useUser()`: Reactive access to the currently signed-in user.
|
|
18
|
+
* - `useSession()`: Reactive access to active session data.
|
|
19
|
+
* - `<SignedIn>` / `<SignedOut>`: Conditional rendering wrappers.
|
|
20
|
+
*
|
|
21
|
+
* @module react
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
type ReactNode = unknown;
|
|
25
|
+
interface ReactContext<T> {
|
|
26
|
+
Provider: unknown;
|
|
27
|
+
Consumer: unknown;
|
|
28
|
+
_currentValue?: T;
|
|
29
|
+
}
|
|
30
|
+
interface ReactRuntime {
|
|
31
|
+
createContext<T>(defaultValue: T): ReactContext<T>;
|
|
32
|
+
useContext<T>(context: ReactContext<T>): T;
|
|
33
|
+
useState<T>(initialState: T | (() => T)): [T, (value: T | ((prev: T) => T)) => void];
|
|
34
|
+
useEffect(effect: () => void | (() => void), deps?: readonly unknown[]): void;
|
|
35
|
+
useMemo<T>(factory: () => T, deps?: readonly unknown[]): T;
|
|
36
|
+
createElement(type: unknown, props?: Record<string, unknown> | null, ...children: unknown[]): unknown;
|
|
37
|
+
Fragment: unknown;
|
|
38
|
+
}
|
|
39
|
+
interface AuthContextValue {
|
|
40
|
+
client: AuraClient | null;
|
|
41
|
+
user: User | null;
|
|
42
|
+
session: Session | null;
|
|
43
|
+
accessToken: string | null;
|
|
44
|
+
isLoading: boolean;
|
|
45
|
+
isAuthenticated: boolean;
|
|
46
|
+
signOut: () => Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
interface AuthProviderProps {
|
|
49
|
+
client: AuraClient;
|
|
50
|
+
children: ReactNode;
|
|
51
|
+
initialSession?: Session | null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Wraps your application to provide reactive Aurabase authentication context.
|
|
55
|
+
*/
|
|
56
|
+
declare function AuthProvider({ client, children, initialSession }: AuthProviderProps): unknown;
|
|
57
|
+
/**
|
|
58
|
+
* Access the core Aurabase authentication state and actions.
|
|
59
|
+
*/
|
|
60
|
+
declare function useAuth(): AuthContextValue;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the currently authenticated user, or null if unauthenticated.
|
|
63
|
+
*/
|
|
64
|
+
declare function useUser(): User | null;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the current active session.
|
|
67
|
+
*/
|
|
68
|
+
declare function useSession(): Session | null;
|
|
69
|
+
/**
|
|
70
|
+
* Conditional component rendering children only when a user is signed in.
|
|
71
|
+
*/
|
|
72
|
+
declare function SignedIn({ children }: {
|
|
73
|
+
children: ReactNode;
|
|
74
|
+
}): unknown;
|
|
75
|
+
/**
|
|
76
|
+
* Conditional component rendering children only when NO user is signed in.
|
|
77
|
+
*/
|
|
78
|
+
declare function SignedOut({ children }: {
|
|
79
|
+
children: ReactNode;
|
|
80
|
+
}): unknown;
|
|
81
|
+
|
|
82
|
+
export { type AuthContextValue, AuthProvider, type AuthProviderProps, type ReactContext, type ReactNode, type ReactRuntime, SignedIn, SignedOut, useAuth, useSession, useUser };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { User, Session } from '@aurabase/core';
|
|
2
|
+
import { A as AuraClient } from './AuraClient-5jDiXjrO.js';
|
|
3
|
+
import '@aurabase/ai';
|
|
4
|
+
import '@aurabase/auth';
|
|
5
|
+
import '@aurabase/db';
|
|
6
|
+
import '@aurabase/functions';
|
|
7
|
+
import '@aurabase/notifications';
|
|
8
|
+
import '@aurabase/realtime';
|
|
9
|
+
import '@aurabase/storage';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* React Context, hooks, and lifecycle primitives for Aurabase Auth.
|
|
13
|
+
*
|
|
14
|
+
* Provides Clerk-level reactive DX:
|
|
15
|
+
* - `<AuthProvider>`: React context managing real-time auth state across the tree.
|
|
16
|
+
* - `useAuth()`: Access client, status, token, and sign-out helpers.
|
|
17
|
+
* - `useUser()`: Reactive access to the currently signed-in user.
|
|
18
|
+
* - `useSession()`: Reactive access to active session data.
|
|
19
|
+
* - `<SignedIn>` / `<SignedOut>`: Conditional rendering wrappers.
|
|
20
|
+
*
|
|
21
|
+
* @module react
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
type ReactNode = unknown;
|
|
25
|
+
interface ReactContext<T> {
|
|
26
|
+
Provider: unknown;
|
|
27
|
+
Consumer: unknown;
|
|
28
|
+
_currentValue?: T;
|
|
29
|
+
}
|
|
30
|
+
interface ReactRuntime {
|
|
31
|
+
createContext<T>(defaultValue: T): ReactContext<T>;
|
|
32
|
+
useContext<T>(context: ReactContext<T>): T;
|
|
33
|
+
useState<T>(initialState: T | (() => T)): [T, (value: T | ((prev: T) => T)) => void];
|
|
34
|
+
useEffect(effect: () => void | (() => void), deps?: readonly unknown[]): void;
|
|
35
|
+
useMemo<T>(factory: () => T, deps?: readonly unknown[]): T;
|
|
36
|
+
createElement(type: unknown, props?: Record<string, unknown> | null, ...children: unknown[]): unknown;
|
|
37
|
+
Fragment: unknown;
|
|
38
|
+
}
|
|
39
|
+
interface AuthContextValue {
|
|
40
|
+
client: AuraClient | null;
|
|
41
|
+
user: User | null;
|
|
42
|
+
session: Session | null;
|
|
43
|
+
accessToken: string | null;
|
|
44
|
+
isLoading: boolean;
|
|
45
|
+
isAuthenticated: boolean;
|
|
46
|
+
signOut: () => Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
interface AuthProviderProps {
|
|
49
|
+
client: AuraClient;
|
|
50
|
+
children: ReactNode;
|
|
51
|
+
initialSession?: Session | null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Wraps your application to provide reactive Aurabase authentication context.
|
|
55
|
+
*/
|
|
56
|
+
declare function AuthProvider({ client, children, initialSession }: AuthProviderProps): unknown;
|
|
57
|
+
/**
|
|
58
|
+
* Access the core Aurabase authentication state and actions.
|
|
59
|
+
*/
|
|
60
|
+
declare function useAuth(): AuthContextValue;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the currently authenticated user, or null if unauthenticated.
|
|
63
|
+
*/
|
|
64
|
+
declare function useUser(): User | null;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the current active session.
|
|
67
|
+
*/
|
|
68
|
+
declare function useSession(): Session | null;
|
|
69
|
+
/**
|
|
70
|
+
* Conditional component rendering children only when a user is signed in.
|
|
71
|
+
*/
|
|
72
|
+
declare function SignedIn({ children }: {
|
|
73
|
+
children: ReactNode;
|
|
74
|
+
}): unknown;
|
|
75
|
+
/**
|
|
76
|
+
* Conditional component rendering children only when NO user is signed in.
|
|
77
|
+
*/
|
|
78
|
+
declare function SignedOut({ children }: {
|
|
79
|
+
children: ReactNode;
|
|
80
|
+
}): unknown;
|
|
81
|
+
|
|
82
|
+
export { type AuthContextValue, AuthProvider, type AuthProviderProps, type ReactContext, type ReactNode, type ReactRuntime, SignedIn, SignedOut, useAuth, useSession, useUser };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/react.ts
|
|
9
|
+
function getReact() {
|
|
10
|
+
const g = globalThis;
|
|
11
|
+
if (g.React) {
|
|
12
|
+
return g.React;
|
|
13
|
+
}
|
|
14
|
+
if (typeof __require === "function") {
|
|
15
|
+
try {
|
|
16
|
+
return __require("react");
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
var defaultAuthContextValue = {
|
|
24
|
+
client: null,
|
|
25
|
+
user: null,
|
|
26
|
+
session: null,
|
|
27
|
+
accessToken: null,
|
|
28
|
+
isLoading: true,
|
|
29
|
+
isAuthenticated: false,
|
|
30
|
+
signOut: async () => {
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var authContextInstance = null;
|
|
34
|
+
function getAuthContext() {
|
|
35
|
+
if (!authContextInstance) {
|
|
36
|
+
const React = getReact();
|
|
37
|
+
if (React?.createContext) {
|
|
38
|
+
authContextInstance = React.createContext(defaultAuthContextValue);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return authContextInstance;
|
|
42
|
+
}
|
|
43
|
+
function AuthProvider({ client, children, initialSession = null }) {
|
|
44
|
+
const React = getReact();
|
|
45
|
+
if (!React) {
|
|
46
|
+
throw new Error("[@aurabase/react] React est requis pour utiliser <AuthProvider>.");
|
|
47
|
+
}
|
|
48
|
+
const [session, setSession] = React.useState(initialSession);
|
|
49
|
+
const [user, setUser] = React.useState(initialSession?.user ?? null);
|
|
50
|
+
const [isLoading, setIsLoading] = React.useState(!initialSession);
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
let isMounted = true;
|
|
53
|
+
void client.auth.getSession().then(({ data }) => {
|
|
54
|
+
if (!isMounted) return;
|
|
55
|
+
const s = data?.session ?? null;
|
|
56
|
+
setSession(s);
|
|
57
|
+
setUser(s?.user ?? null);
|
|
58
|
+
setIsLoading(false);
|
|
59
|
+
}).catch(() => {
|
|
60
|
+
if (!isMounted) return;
|
|
61
|
+
setIsLoading(false);
|
|
62
|
+
});
|
|
63
|
+
const subscription = client.auth.onAuthStateChange(({ event, user: nextUser }) => {
|
|
64
|
+
if (!isMounted) return;
|
|
65
|
+
if (event === "SIGNED_OUT") {
|
|
66
|
+
setSession(null);
|
|
67
|
+
setUser(null);
|
|
68
|
+
} else if (event === "SIGNED_IN" || event === "TOKEN_REFRESHED" || event === "USER_UPDATED") {
|
|
69
|
+
void client.auth.getSession().then(({ data }) => {
|
|
70
|
+
if (!isMounted) return;
|
|
71
|
+
const s = data?.session ?? null;
|
|
72
|
+
setSession(s);
|
|
73
|
+
setUser(nextUser ?? s?.user ?? null);
|
|
74
|
+
}).catch(() => {
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return () => {
|
|
79
|
+
isMounted = false;
|
|
80
|
+
subscription.unsubscribe();
|
|
81
|
+
};
|
|
82
|
+
}, [client]);
|
|
83
|
+
const value = React.useMemo(
|
|
84
|
+
() => ({
|
|
85
|
+
client,
|
|
86
|
+
user,
|
|
87
|
+
session,
|
|
88
|
+
accessToken: session?.access_token ?? null,
|
|
89
|
+
isLoading,
|
|
90
|
+
isAuthenticated: !!user,
|
|
91
|
+
signOut: async () => {
|
|
92
|
+
await client.auth.signOut();
|
|
93
|
+
setSession(null);
|
|
94
|
+
setUser(null);
|
|
95
|
+
}
|
|
96
|
+
}),
|
|
97
|
+
[client, user, session, isLoading]
|
|
98
|
+
);
|
|
99
|
+
const Context = getAuthContext();
|
|
100
|
+
if (!Context) {
|
|
101
|
+
return children;
|
|
102
|
+
}
|
|
103
|
+
return React.createElement(Context.Provider, { value }, children);
|
|
104
|
+
}
|
|
105
|
+
function useAuth() {
|
|
106
|
+
const React = getReact();
|
|
107
|
+
const Context = getAuthContext();
|
|
108
|
+
if (!React || !Context) {
|
|
109
|
+
return {
|
|
110
|
+
client: null,
|
|
111
|
+
user: null,
|
|
112
|
+
session: null,
|
|
113
|
+
accessToken: null,
|
|
114
|
+
isLoading: false,
|
|
115
|
+
isAuthenticated: false,
|
|
116
|
+
signOut: async () => {
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return React.useContext(Context);
|
|
121
|
+
}
|
|
122
|
+
function useUser() {
|
|
123
|
+
const { user } = useAuth();
|
|
124
|
+
return user;
|
|
125
|
+
}
|
|
126
|
+
function useSession() {
|
|
127
|
+
const { session } = useAuth();
|
|
128
|
+
return session;
|
|
129
|
+
}
|
|
130
|
+
function SignedIn({ children }) {
|
|
131
|
+
const React = getReact();
|
|
132
|
+
const { isAuthenticated, isLoading } = useAuth();
|
|
133
|
+
if (isLoading || !isAuthenticated || !React) return null;
|
|
134
|
+
return React.createElement(React.Fragment, null, children);
|
|
135
|
+
}
|
|
136
|
+
function SignedOut({ children }) {
|
|
137
|
+
const React = getReact();
|
|
138
|
+
const { isAuthenticated, isLoading } = useAuth();
|
|
139
|
+
if (isLoading || isAuthenticated || !React) return null;
|
|
140
|
+
return React.createElement(React.Fragment, null, children);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { AuthProvider, SignedIn, SignedOut, useAuth, useSession, useUser };
|
package/dist/ssr.cjs
CHANGED
|
@@ -63,6 +63,11 @@ var AuraClient = class {
|
|
|
63
63
|
"[aurabase] No API key provided. Most operations require an API key (apikey header). Only public auth routes (register, login, refresh) will work without one."
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
|
+
if (typeof console !== "undefined" && /^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?\/?$/.test(this.baseUrl)) {
|
|
67
|
+
console.warn(
|
|
68
|
+
"[aurabase] Attention : en local, l'URL du projet doit inclure le sous-domaine (ex: http://<slug>.localhost:8080) pour permettre la r\xE9solution automatique du projet par la passerelle."
|
|
69
|
+
);
|
|
70
|
+
}
|
|
66
71
|
if (this.apiKey?.startsWith(SERVICE_ROLE_KEY_PREFIX) && isBrowserContext()) {
|
|
67
72
|
const refuse = resolvedOptions?.refuseServiceRoleInBrowser ?? true;
|
|
68
73
|
const message = "[aurabase] S\xC9CURIT\xC9 : une cl\xE9 service_role (aura_sk_\u2026) est fournie \xE0 createClient() dans un contexte navigateur. Cette cl\xE9 \xE0 privil\xE8ges \xE9lev\xE9s NE DOIT JAMAIS \xEAtre expos\xE9e c\xF4t\xE9 client (elle fuiterait dans le bundle). Utilisez une cl\xE9 anon (aura_anon_\u2026) c\xF4t\xE9 client, et createAdminClient() c\xF4t\xE9 serveur pour les op\xE9rations d'administration.";
|
|
@@ -76,7 +81,12 @@ var AuraClient = class {
|
|
|
76
81
|
this.authStore = resolvedOptions.auth.storage;
|
|
77
82
|
} else if (resolvedOptions?.auth?.persistSession === false) {
|
|
78
83
|
this.authStore = new core.BaseAuthStore();
|
|
79
|
-
} else if (typeof localStorage !== "undefined") {
|
|
84
|
+
} else if (isBrowserContext() && typeof window.localStorage !== "undefined" || typeof globalThis !== "undefined" && (() => {
|
|
85
|
+
const g = globalThis;
|
|
86
|
+
const proc = g?.process;
|
|
87
|
+
const isTest = !!(proc?.env?.VITEST || proc?.env?.NODE_ENV === "test" || proc?.env?.JEST_WORKER_ID);
|
|
88
|
+
return isTest && !!g?.localStorage && typeof g.localStorage.getItem === "function";
|
|
89
|
+
})()) {
|
|
80
90
|
this.authStore = new core.LocalAuthStore(`aura-${core.clientScope(this.baseUrl)}-auth`);
|
|
81
91
|
} else {
|
|
82
92
|
this.authStore = new core.BaseAuthStore();
|
|
@@ -153,6 +163,21 @@ var AuraClient = class {
|
|
|
153
163
|
if (!this._notifications) this._notifications = new notifications.NotificationsService(this);
|
|
154
164
|
return this._notifications;
|
|
155
165
|
}
|
|
166
|
+
from(table) {
|
|
167
|
+
return this.db.from(table);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Shortcut: call a stored procedure / PostgreSQL function via RPC (Supabase-compatible API).
|
|
171
|
+
* Equivalent to `aura.db.rpc(fn, args, options)`.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* const { data, error } = await aura.rpc('echo_test', { message: 'hello' })
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
rpc(fn, args, options) {
|
|
179
|
+
return this.db.rpc(fn, args, options);
|
|
180
|
+
}
|
|
156
181
|
/**
|
|
157
182
|
* Shortcut: create a realtime channel with Supabase-compatible API.
|
|
158
183
|
* Equivalent to `aura.realtime.channel(name)`.
|
package/dist/ssr.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SerializeCookieOptions, AuraClientOptions } from '@aurabase/core';
|
|
2
2
|
export { SerializeCookieOptions, parseCookieHeader, serializeCookieHeader } from '@aurabase/core';
|
|
3
|
-
import { A as AuraClient } from './AuraClient-
|
|
3
|
+
import { A as AuraClient } from './AuraClient-5jDiXjrO.cjs';
|
|
4
4
|
import '@aurabase/ai';
|
|
5
5
|
import '@aurabase/auth';
|
|
6
6
|
import '@aurabase/db';
|
package/dist/ssr.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SerializeCookieOptions, AuraClientOptions } from '@aurabase/core';
|
|
2
2
|
export { SerializeCookieOptions, parseCookieHeader, serializeCookieHeader } from '@aurabase/core';
|
|
3
|
-
import { A as AuraClient } from './AuraClient-
|
|
3
|
+
import { A as AuraClient } from './AuraClient-5jDiXjrO.js';
|
|
4
4
|
import '@aurabase/ai';
|
|
5
5
|
import '@aurabase/auth';
|
|
6
6
|
import '@aurabase/db';
|
package/dist/ssr.js
CHANGED
|
@@ -62,6 +62,11 @@ var AuraClient = class {
|
|
|
62
62
|
"[aurabase] No API key provided. Most operations require an API key (apikey header). Only public auth routes (register, login, refresh) will work without one."
|
|
63
63
|
);
|
|
64
64
|
}
|
|
65
|
+
if (typeof console !== "undefined" && /^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?\/?$/.test(this.baseUrl)) {
|
|
66
|
+
console.warn(
|
|
67
|
+
"[aurabase] Attention : en local, l'URL du projet doit inclure le sous-domaine (ex: http://<slug>.localhost:8080) pour permettre la r\xE9solution automatique du projet par la passerelle."
|
|
68
|
+
);
|
|
69
|
+
}
|
|
65
70
|
if (this.apiKey?.startsWith(SERVICE_ROLE_KEY_PREFIX) && isBrowserContext()) {
|
|
66
71
|
const refuse = resolvedOptions?.refuseServiceRoleInBrowser ?? true;
|
|
67
72
|
const message = "[aurabase] S\xC9CURIT\xC9 : une cl\xE9 service_role (aura_sk_\u2026) est fournie \xE0 createClient() dans un contexte navigateur. Cette cl\xE9 \xE0 privil\xE8ges \xE9lev\xE9s NE DOIT JAMAIS \xEAtre expos\xE9e c\xF4t\xE9 client (elle fuiterait dans le bundle). Utilisez une cl\xE9 anon (aura_anon_\u2026) c\xF4t\xE9 client, et createAdminClient() c\xF4t\xE9 serveur pour les op\xE9rations d'administration.";
|
|
@@ -75,7 +80,12 @@ var AuraClient = class {
|
|
|
75
80
|
this.authStore = resolvedOptions.auth.storage;
|
|
76
81
|
} else if (resolvedOptions?.auth?.persistSession === false) {
|
|
77
82
|
this.authStore = new BaseAuthStore();
|
|
78
|
-
} else if (typeof localStorage !== "undefined") {
|
|
83
|
+
} else if (isBrowserContext() && typeof window.localStorage !== "undefined" || typeof globalThis !== "undefined" && (() => {
|
|
84
|
+
const g = globalThis;
|
|
85
|
+
const proc = g?.process;
|
|
86
|
+
const isTest = !!(proc?.env?.VITEST || proc?.env?.NODE_ENV === "test" || proc?.env?.JEST_WORKER_ID);
|
|
87
|
+
return isTest && !!g?.localStorage && typeof g.localStorage.getItem === "function";
|
|
88
|
+
})()) {
|
|
79
89
|
this.authStore = new LocalAuthStore(`aura-${clientScope(this.baseUrl)}-auth`);
|
|
80
90
|
} else {
|
|
81
91
|
this.authStore = new BaseAuthStore();
|
|
@@ -152,6 +162,21 @@ var AuraClient = class {
|
|
|
152
162
|
if (!this._notifications) this._notifications = new NotificationsService(this);
|
|
153
163
|
return this._notifications;
|
|
154
164
|
}
|
|
165
|
+
from(table) {
|
|
166
|
+
return this.db.from(table);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Shortcut: call a stored procedure / PostgreSQL function via RPC (Supabase-compatible API).
|
|
170
|
+
* Equivalent to `aura.db.rpc(fn, args, options)`.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const { data, error } = await aura.rpc('echo_test', { message: 'hello' })
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
rpc(fn, args, options) {
|
|
178
|
+
return this.db.rpc(fn, args, options);
|
|
179
|
+
}
|
|
155
180
|
/**
|
|
156
181
|
* Shortcut: create a realtime channel with Supabase-compatible API.
|
|
157
182
|
* Equivalent to `aura.realtime.channel(name)`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aurabase/aurabase-js",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Official JavaScript/TypeScript client for Aurabase BaaS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -26,6 +26,26 @@
|
|
|
26
26
|
"types": "./dist/ssr.d.cts",
|
|
27
27
|
"default": "./dist/ssr.cjs"
|
|
28
28
|
}
|
|
29
|
+
},
|
|
30
|
+
"./nextjs": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/nextjs.d.ts",
|
|
33
|
+
"default": "./dist/nextjs.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/nextjs.d.cts",
|
|
37
|
+
"default": "./dist/nextjs.cjs"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"./react": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/react.d.ts",
|
|
43
|
+
"default": "./dist/react.js"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/react.d.cts",
|
|
47
|
+
"default": "./dist/react.cjs"
|
|
48
|
+
}
|
|
29
49
|
}
|
|
30
50
|
},
|
|
31
51
|
"sideEffects": false,
|
|
@@ -56,14 +76,14 @@
|
|
|
56
76
|
"client"
|
|
57
77
|
],
|
|
58
78
|
"dependencies": {
|
|
59
|
-
"@aurabase/
|
|
60
|
-
"@aurabase/
|
|
61
|
-
"@aurabase/
|
|
62
|
-
"@aurabase/
|
|
63
|
-
"@aurabase/
|
|
64
|
-
"@aurabase/notifications": "0.5.
|
|
65
|
-
"@aurabase/ai": "0.5.
|
|
66
|
-
"@aurabase/functions": "0.5.
|
|
79
|
+
"@aurabase/db": "0.5.4",
|
|
80
|
+
"@aurabase/core": "0.5.4",
|
|
81
|
+
"@aurabase/auth": "0.5.4",
|
|
82
|
+
"@aurabase/realtime": "0.5.4",
|
|
83
|
+
"@aurabase/storage": "0.5.4",
|
|
84
|
+
"@aurabase/notifications": "0.5.4",
|
|
85
|
+
"@aurabase/ai": "0.5.4",
|
|
86
|
+
"@aurabase/functions": "0.5.4"
|
|
67
87
|
},
|
|
68
88
|
"devDependencies": {
|
|
69
89
|
"@types/node": "20.14.15",
|