@reauth-dev/sdk 0.2.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/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createReauthClient
3
- } from "./chunk-DMNMTW2C.mjs";
3
+ } from "./chunk-5LFJ5PXQ.mjs";
4
4
  import "./chunk-EY5LQCDG.mjs";
5
5
 
6
6
  // src/errors.ts
@@ -1,4 +1,4 @@
1
- import { R as ReauthConfig, c as User } from '../types-BqZzje-y.mjs';
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
 
@@ -43,6 +43,66 @@ declare function useAuth(config: UseAuthOptions): {
43
43
  waitlistPosition: number | null;
44
44
  };
45
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
+
46
106
  type AuthContextType = {
47
107
  user: User | null;
48
108
  loading: boolean;
@@ -130,4 +190,4 @@ type ProtectedRouteProps = {
130
190
  */
131
191
  declare function ProtectedRoute({ children, fallback, onUnauthenticated, onWaitlist, }: ProtectedRouteProps): react_jsx_runtime.JSX.Element | null;
132
192
 
133
- export { AuthProvider, ProtectedRoute, type UseAuthOptions, useAuth, useAuthContext };
193
+ export { AuthProvider, ProtectedRoute, type UseAuthOptions, type UseHeadlessAuthOptions, useAuth, useAuthContext, useHeadlessAuth };
@@ -1,4 +1,4 @@
1
- import { R as ReauthConfig, c as User } from '../types-BqZzje-y.js';
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
 
@@ -43,6 +43,66 @@ declare function useAuth(config: UseAuthOptions): {
43
43
  waitlistPosition: number | null;
44
44
  };
45
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
+
46
106
  type AuthContextType = {
47
107
  user: User | null;
48
108
  loading: boolean;
@@ -130,4 +190,4 @@ type ProtectedRouteProps = {
130
190
  */
131
191
  declare function ProtectedRoute({ children, fallback, onUnauthenticated, onWaitlist, }: ProtectedRouteProps): react_jsx_runtime.JSX.Element | null;
132
192
 
133
- export { AuthProvider, ProtectedRoute, type UseAuthOptions, useAuth, useAuthContext };
193
+ export { AuthProvider, ProtectedRoute, type UseAuthOptions, type UseHeadlessAuthOptions, useAuth, useAuthContext, useHeadlessAuth };