@reauth-dev/sdk 0.1.0 → 0.3.0
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/chunk-5LFJ5PXQ.mjs +1042 -0
- package/dist/chunk-EY5LQCDG.mjs +6 -0
- package/dist/index.d.mts +201 -16
- package/dist/index.d.ts +201 -16
- package/dist/index.js +801 -29
- package/dist/index.mjs +2 -1
- package/dist/react/index.d.mts +75 -5
- package/dist/react/index.d.ts +75 -5
- package/dist/react/index.js +965 -44
- package/dist/react/index.mjs +160 -11
- package/dist/server.d.mts +20 -2
- package/dist/server.d.ts +20 -2
- package/dist/server.js +61 -12
- package/dist/server.mjs +57 -11
- package/dist/types-DKUKhCNE.d.mts +349 -0
- package/dist/types-DKUKhCNE.d.ts +349 -0
- package/dist/webhooks.js +7 -3
- package/dist/webhooks.mjs +7 -3
- package/package.json +5 -2
- package/dist/chunk-JX2J36FS.mjs +0 -269
- package/dist/types-D8oOYbeC.d.mts +0 -169
- package/dist/types-D8oOYbeC.d.ts +0 -169
package/dist/index.mjs
CHANGED
package/dist/react/index.d.mts
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import { R as ReauthConfig,
|
|
1
|
+
import { R as ReauthConfig, o as User, D as DomainConfig, M as MagicLinkVerifyResult, G as GoogleOAuthStartResult, c as TwitterOAuthStartResult } from '../types-DKUKhCNE.mjs';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
4
|
|
|
5
|
+
type UseAuthOptions = ReauthConfig & {
|
|
6
|
+
/**
|
|
7
|
+
* Interval in milliseconds to refresh the session. Set to 0 to disable.
|
|
8
|
+
* Default: 5 minutes (300000ms)
|
|
9
|
+
*/
|
|
10
|
+
refreshInterval?: number;
|
|
11
|
+
};
|
|
5
12
|
/**
|
|
6
13
|
* React hook for authentication state management.
|
|
7
14
|
*
|
|
8
15
|
* @example
|
|
9
16
|
* ```typescript
|
|
10
17
|
* function MyComponent() {
|
|
11
|
-
* const { user, loading, login, logout } = useAuth({
|
|
18
|
+
* const { user, loading, login, logout } = useAuth({
|
|
19
|
+
* domain: 'yourdomain.com',
|
|
20
|
+
* refreshInterval: 60000, // Refresh every minute (optional, default: 5 min)
|
|
21
|
+
* });
|
|
12
22
|
*
|
|
13
23
|
* if (loading) return <div>Loading...</div>;
|
|
14
24
|
* if (!user) return <button onClick={login}>Sign in</button>;
|
|
@@ -22,7 +32,7 @@ import { ReactNode } from 'react';
|
|
|
22
32
|
* }
|
|
23
33
|
* ```
|
|
24
34
|
*/
|
|
25
|
-
declare function useAuth(config:
|
|
35
|
+
declare function useAuth(config: UseAuthOptions): {
|
|
26
36
|
login: () => void;
|
|
27
37
|
logout: () => Promise<void>;
|
|
28
38
|
refetch: () => Promise<void>;
|
|
@@ -33,6 +43,66 @@ declare function useAuth(config: ReauthConfig): {
|
|
|
33
43
|
waitlistPosition: number | null;
|
|
34
44
|
};
|
|
35
45
|
|
|
46
|
+
type HeadlessStep = "idle" | "magic_link_sent" | "google_started" | "twitter_started" | "completed";
|
|
47
|
+
type UseHeadlessAuthOptions = {
|
|
48
|
+
domain: string;
|
|
49
|
+
callbackUrl?: string;
|
|
50
|
+
timeout?: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* React hook for headless authentication (custom UI login).
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* function LoginPage() {
|
|
58
|
+
* const {
|
|
59
|
+
* requestMagicLink,
|
|
60
|
+
* verifyMagicLink,
|
|
61
|
+
* startGoogleOAuth,
|
|
62
|
+
* loading,
|
|
63
|
+
* error,
|
|
64
|
+
* step,
|
|
65
|
+
* } = useHeadlessAuth({
|
|
66
|
+
* domain: 'yourdomain.com',
|
|
67
|
+
* callbackUrl: 'https://app.yourdomain.com/auth/verify',
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* if (step === 'magic_link_sent') {
|
|
71
|
+
* return <p>Check your email for a magic link!</p>;
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
* if (step === 'completed') {
|
|
75
|
+
* return <p>Authenticated!</p>;
|
|
76
|
+
* }
|
|
77
|
+
*
|
|
78
|
+
* return (
|
|
79
|
+
* <div>
|
|
80
|
+
* <button onClick={() => requestMagicLink('user@example.com')}>
|
|
81
|
+
* Send Magic Link
|
|
82
|
+
* </button>
|
|
83
|
+
* <button onClick={startGoogleOAuth}>
|
|
84
|
+
* Sign in with Google
|
|
85
|
+
* </button>
|
|
86
|
+
* {error && <p>{error}</p>}
|
|
87
|
+
* </div>
|
|
88
|
+
* );
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare function useHeadlessAuth(options: UseHeadlessAuthOptions): {
|
|
93
|
+
getConfig: () => Promise<DomainConfig>;
|
|
94
|
+
requestMagicLink: (email: string) => Promise<void>;
|
|
95
|
+
verifyMagicLink: (token: string) => Promise<MagicLinkVerifyResult>;
|
|
96
|
+
startGoogleOAuth: () => Promise<GoogleOAuthStartResult>;
|
|
97
|
+
startTwitterOAuth: () => Promise<TwitterOAuthStartResult>;
|
|
98
|
+
reset: () => void;
|
|
99
|
+
loading: boolean;
|
|
100
|
+
error: string | null;
|
|
101
|
+
step: HeadlessStep;
|
|
102
|
+
config: DomainConfig | null;
|
|
103
|
+
verifyResult: MagicLinkVerifyResult | null;
|
|
104
|
+
};
|
|
105
|
+
|
|
36
106
|
type AuthContextType = {
|
|
37
107
|
user: User | null;
|
|
38
108
|
loading: boolean;
|
|
@@ -44,7 +114,7 @@ type AuthContextType = {
|
|
|
44
114
|
refetch: () => Promise<void>;
|
|
45
115
|
};
|
|
46
116
|
type AuthProviderProps = {
|
|
47
|
-
config:
|
|
117
|
+
config: UseAuthOptions;
|
|
48
118
|
children: ReactNode;
|
|
49
119
|
};
|
|
50
120
|
/**
|
|
@@ -120,4 +190,4 @@ type ProtectedRouteProps = {
|
|
|
120
190
|
*/
|
|
121
191
|
declare function ProtectedRoute({ children, fallback, onUnauthenticated, onWaitlist, }: ProtectedRouteProps): react_jsx_runtime.JSX.Element | null;
|
|
122
192
|
|
|
123
|
-
export { AuthProvider, ProtectedRoute, useAuth, useAuthContext };
|
|
193
|
+
export { AuthProvider, ProtectedRoute, type UseAuthOptions, type UseHeadlessAuthOptions, useAuth, useAuthContext, useHeadlessAuth };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import { R as ReauthConfig,
|
|
1
|
+
import { R as ReauthConfig, o as User, D as DomainConfig, M as MagicLinkVerifyResult, G as GoogleOAuthStartResult, c as TwitterOAuthStartResult } from '../types-DKUKhCNE.js';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
4
|
|
|
5
|
+
type UseAuthOptions = ReauthConfig & {
|
|
6
|
+
/**
|
|
7
|
+
* Interval in milliseconds to refresh the session. Set to 0 to disable.
|
|
8
|
+
* Default: 5 minutes (300000ms)
|
|
9
|
+
*/
|
|
10
|
+
refreshInterval?: number;
|
|
11
|
+
};
|
|
5
12
|
/**
|
|
6
13
|
* React hook for authentication state management.
|
|
7
14
|
*
|
|
8
15
|
* @example
|
|
9
16
|
* ```typescript
|
|
10
17
|
* function MyComponent() {
|
|
11
|
-
* const { user, loading, login, logout } = useAuth({
|
|
18
|
+
* const { user, loading, login, logout } = useAuth({
|
|
19
|
+
* domain: 'yourdomain.com',
|
|
20
|
+
* refreshInterval: 60000, // Refresh every minute (optional, default: 5 min)
|
|
21
|
+
* });
|
|
12
22
|
*
|
|
13
23
|
* if (loading) return <div>Loading...</div>;
|
|
14
24
|
* if (!user) return <button onClick={login}>Sign in</button>;
|
|
@@ -22,7 +32,7 @@ import { ReactNode } from 'react';
|
|
|
22
32
|
* }
|
|
23
33
|
* ```
|
|
24
34
|
*/
|
|
25
|
-
declare function useAuth(config:
|
|
35
|
+
declare function useAuth(config: UseAuthOptions): {
|
|
26
36
|
login: () => void;
|
|
27
37
|
logout: () => Promise<void>;
|
|
28
38
|
refetch: () => Promise<void>;
|
|
@@ -33,6 +43,66 @@ declare function useAuth(config: ReauthConfig): {
|
|
|
33
43
|
waitlistPosition: number | null;
|
|
34
44
|
};
|
|
35
45
|
|
|
46
|
+
type HeadlessStep = "idle" | "magic_link_sent" | "google_started" | "twitter_started" | "completed";
|
|
47
|
+
type UseHeadlessAuthOptions = {
|
|
48
|
+
domain: string;
|
|
49
|
+
callbackUrl?: string;
|
|
50
|
+
timeout?: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* React hook for headless authentication (custom UI login).
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* function LoginPage() {
|
|
58
|
+
* const {
|
|
59
|
+
* requestMagicLink,
|
|
60
|
+
* verifyMagicLink,
|
|
61
|
+
* startGoogleOAuth,
|
|
62
|
+
* loading,
|
|
63
|
+
* error,
|
|
64
|
+
* step,
|
|
65
|
+
* } = useHeadlessAuth({
|
|
66
|
+
* domain: 'yourdomain.com',
|
|
67
|
+
* callbackUrl: 'https://app.yourdomain.com/auth/verify',
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* if (step === 'magic_link_sent') {
|
|
71
|
+
* return <p>Check your email for a magic link!</p>;
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
* if (step === 'completed') {
|
|
75
|
+
* return <p>Authenticated!</p>;
|
|
76
|
+
* }
|
|
77
|
+
*
|
|
78
|
+
* return (
|
|
79
|
+
* <div>
|
|
80
|
+
* <button onClick={() => requestMagicLink('user@example.com')}>
|
|
81
|
+
* Send Magic Link
|
|
82
|
+
* </button>
|
|
83
|
+
* <button onClick={startGoogleOAuth}>
|
|
84
|
+
* Sign in with Google
|
|
85
|
+
* </button>
|
|
86
|
+
* {error && <p>{error}</p>}
|
|
87
|
+
* </div>
|
|
88
|
+
* );
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare function useHeadlessAuth(options: UseHeadlessAuthOptions): {
|
|
93
|
+
getConfig: () => Promise<DomainConfig>;
|
|
94
|
+
requestMagicLink: (email: string) => Promise<void>;
|
|
95
|
+
verifyMagicLink: (token: string) => Promise<MagicLinkVerifyResult>;
|
|
96
|
+
startGoogleOAuth: () => Promise<GoogleOAuthStartResult>;
|
|
97
|
+
startTwitterOAuth: () => Promise<TwitterOAuthStartResult>;
|
|
98
|
+
reset: () => void;
|
|
99
|
+
loading: boolean;
|
|
100
|
+
error: string | null;
|
|
101
|
+
step: HeadlessStep;
|
|
102
|
+
config: DomainConfig | null;
|
|
103
|
+
verifyResult: MagicLinkVerifyResult | null;
|
|
104
|
+
};
|
|
105
|
+
|
|
36
106
|
type AuthContextType = {
|
|
37
107
|
user: User | null;
|
|
38
108
|
loading: boolean;
|
|
@@ -44,7 +114,7 @@ type AuthContextType = {
|
|
|
44
114
|
refetch: () => Promise<void>;
|
|
45
115
|
};
|
|
46
116
|
type AuthProviderProps = {
|
|
47
|
-
config:
|
|
117
|
+
config: UseAuthOptions;
|
|
48
118
|
children: ReactNode;
|
|
49
119
|
};
|
|
50
120
|
/**
|
|
@@ -120,4 +190,4 @@ type ProtectedRouteProps = {
|
|
|
120
190
|
*/
|
|
121
191
|
declare function ProtectedRoute({ children, fallback, onUnauthenticated, onWaitlist, }: ProtectedRouteProps): react_jsx_runtime.JSX.Element | null;
|
|
122
192
|
|
|
123
|
-
export { AuthProvider, ProtectedRoute, useAuth, useAuthContext };
|
|
193
|
+
export { AuthProvider, ProtectedRoute, type UseAuthOptions, type UseHeadlessAuthOptions, useAuth, useAuthContext, useHeadlessAuth };
|