@digilogiclabs/saas-factory-auth 0.4.1 → 0.4.3

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.d.mts CHANGED
@@ -1,9 +1,91 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
1
+ import React from 'react';
3
2
  import * as _supabase_supabase_js from '@supabase/supabase-js';
4
3
  import { NextRequest, NextResponse } from 'next/server.js';
5
4
  import { ReadonlyRequestCookies } from 'next/dist/server/web/spec-extension/adapters/request-cookies';
6
5
 
6
+ /**
7
+ * OAuth provider types - re-export from types for backward compatibility
8
+ */
9
+ type OAuthProvider$1 = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
10
+ /**
11
+ * Authentication provider interface that abstracts authentication operations
12
+ * across different backends (Supabase, Firebase, etc.)
13
+ */
14
+ interface IAuthProvider {
15
+ /**
16
+ * Sign in with email and password
17
+ * @param email User's email address
18
+ * @param password User's password (required for email/password authentication)
19
+ * @returns Promise resolving to an object containing user, session, and error
20
+ */
21
+ signIn(email: string, password: string): Promise<{
22
+ user: User | null;
23
+ session: AuthSession | null;
24
+ error: any;
25
+ }>;
26
+ /**
27
+ * Sign up with email and password
28
+ * @param email User's email address
29
+ * @param password User's password (required for email/password authentication)
30
+ * @returns Promise resolving to an object containing user, session, and error
31
+ */
32
+ signUp(email: string, password: string): Promise<{
33
+ user: User | null;
34
+ session: AuthSession | null;
35
+ error: any;
36
+ }>;
37
+ /**
38
+ * Sign in with OAuth provider
39
+ * @param provider OAuth provider name
40
+ * @param redirectTo Optional redirect URL after authentication
41
+ * @returns Promise that resolves when OAuth flow is initiated
42
+ */
43
+ signInWithOAuth(provider: OAuthProvider$1, redirectTo?: string): Promise<void>;
44
+ /**
45
+ * Sign in with magic link (passwordless authentication)
46
+ * @param email User's email address
47
+ * @param redirectTo Optional redirect URL after email verification
48
+ * @returns Promise that resolves when magic link is sent
49
+ */
50
+ signInWithMagicLink(email: string, redirectTo?: string): Promise<void>;
51
+ /**
52
+ * Sign out the current user
53
+ * @returns Promise resolving to an object containing error
54
+ */
55
+ signOut(): Promise<{
56
+ error: any;
57
+ }>;
58
+ /**
59
+ * Get the current authenticated user
60
+ * @returns Promise resolving to the current user or null if not authenticated
61
+ */
62
+ getUser(): Promise<User | null>;
63
+ /**
64
+ * Get the current authentication session
65
+ * @returns Promise resolving to the current session or null if not authenticated
66
+ */
67
+ getSession(): Promise<AuthSession | null>;
68
+ /**
69
+ * Send password reset email
70
+ * @param email User's email address
71
+ * @returns Promise resolving to an object containing error
72
+ */
73
+ resetPassword(email: string): Promise<{
74
+ error: any;
75
+ }>;
76
+ /**
77
+ * Listen for authentication state changes
78
+ * @param callback Function called when auth state changes
79
+ * @returns Object containing subscription data for cleanup
80
+ */
81
+ onAuthStateChange(callback: (event: AuthEvent, session: AuthSession | null) => void): any;
82
+ /**
83
+ * Validate provider configuration
84
+ * @returns Promise that resolves if configuration is valid
85
+ */
86
+ validateConfiguration?(): Promise<void>;
87
+ }
88
+
7
89
  /**
8
90
  * User interface representing authenticated user data
9
91
  */
@@ -36,7 +118,7 @@ declare enum AuthEvent {
36
118
  /**
37
119
  * OAuth provider types supported by the auth system
38
120
  */
39
- type OAuthProvider$1 = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
121
+ type OAuthProvider = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
40
122
  /**
41
123
  * Authentication form modes
42
124
  */
@@ -83,119 +165,46 @@ interface AuthFormProps {
83
165
  onSuccess?: () => void;
84
166
  onError?: (error: Error) => void;
85
167
  redirectTo?: string;
86
- providers?: OAuthProvider$1[];
168
+ providers?: OAuthProvider[];
87
169
  allowMagicLink?: boolean;
88
170
  className?: string;
89
171
  }
90
- /**
91
- * Zustand store interface for authentication state and actions
92
- * This represents the actual store hook that components will use
93
- */
172
+
94
173
  interface AuthStore {
95
174
  user: User | null;
175
+ session: AuthSession | null;
96
176
  loading: boolean;
97
- error: string | null;
98
- updateUser: (user: User | null) => void;
177
+ error: Error | null;
178
+ setUser: (user: User | null) => void;
179
+ setSession: (session: AuthSession | null) => void;
99
180
  setLoading: (loading: boolean) => void;
100
- setError: (error: string | null) => void;
181
+ setError: (error: Error | null) => void;
182
+ setAuthProvider: (provider: IAuthProvider) => void;
101
183
  signIn: (email: string, password: string) => Promise<void>;
102
184
  signUp: (email: string, password: string) => Promise<void>;
103
185
  signOut: () => Promise<void>;
104
186
  resetPassword: (email: string) => Promise<void>;
105
- signInWithOAuth: (provider: OAuthProvider$1, redirectTo?: string) => Promise<void>;
187
+ signInWithOAuth: (provider: OAuthProvider, redirectTo?: string) => Promise<void>;
106
188
  signInWithMagicLink: (email: string, redirectTo?: string) => Promise<void>;
107
189
  getUser: () => Promise<User | null>;
108
190
  getSession: () => Promise<AuthSession | null>;
109
191
  onAuthStateChange: (callback: (event: AuthEvent, session: AuthSession | null) => void) => any;
110
192
  }
111
- /**
112
- * Type for the actual Zustand hook returned by createAuthStore
113
- * This is what gets passed through context and used by components
114
- */
115
- type AuthStoreHook = () => AuthStore;
116
193
 
117
- /**
118
- * OAuth provider types - re-export from types for backward compatibility
119
- */
120
- type OAuthProvider = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
121
- /**
122
- * Authentication provider interface that abstracts authentication operations
123
- * across different backends (Supabase, Firebase, etc.)
124
- */
125
- interface IAuthProvider {
126
- /**
127
- * Sign in with email and password
128
- * @param email User's email address
129
- * @param password User's password (required for email/password authentication)
130
- * @returns Promise resolving to an object containing user, session, and error
131
- */
132
- signIn(email: string, password: string): Promise<{
133
- user: User | null;
134
- session: AuthSession | null;
135
- error: any;
136
- }>;
137
- /**
138
- * Sign up with email and password
139
- * @param email User's email address
140
- * @param password User's password (required for email/password authentication)
141
- * @returns Promise resolving to an object containing user, session, and error
142
- */
143
- signUp(email: string, password: string): Promise<{
144
- user: User | null;
145
- session: AuthSession | null;
146
- error: any;
147
- }>;
148
- /**
149
- * Sign in with OAuth provider
150
- * @param provider OAuth provider name
151
- * @param redirectTo Optional redirect URL after authentication
152
- * @returns Promise that resolves when OAuth flow is initiated
153
- */
154
- signInWithOAuth(provider: OAuthProvider, redirectTo?: string): Promise<void>;
155
- /**
156
- * Sign in with magic link (passwordless authentication)
157
- * @param email User's email address
158
- * @param redirectTo Optional redirect URL after email verification
159
- * @returns Promise that resolves when magic link is sent
160
- */
161
- signInWithMagicLink(email: string, redirectTo?: string): Promise<void>;
162
- /**
163
- * Sign out the current user
164
- * @returns Promise resolving to an object containing error
165
- */
166
- signOut(): Promise<{
167
- error: any;
168
- }>;
169
- /**
170
- * Get the current authenticated user
171
- * @returns Promise resolving to the current user or null if not authenticated
172
- */
173
- getUser(): Promise<User | null>;
174
- /**
175
- * Get the current authentication session
176
- * @returns Promise resolving to the current session or null if not authenticated
177
- */
178
- getSession(): Promise<AuthSession | null>;
179
- /**
180
- * Send password reset email
181
- * @param email User's email address
182
- * @returns Promise resolving to an object containing error
183
- */
184
- resetPassword(email: string): Promise<{
185
- error: any;
186
- }>;
187
- /**
188
- * Listen for authentication state changes
189
- * @param callback Function called when auth state changes
190
- * @returns Object containing subscription data for cleanup
191
- */
192
- onAuthStateChange(callback: (event: AuthEvent, session: AuthSession | null) => void): any;
193
- /**
194
- * Validate provider configuration
195
- * @returns Promise that resolves if configuration is valid
196
- */
197
- validateConfiguration?(): Promise<void>;
194
+ interface AuthProviderProps {
195
+ children: React.ReactNode;
196
+ onAuthChange?: (event: AuthEvent) => void;
197
+ autoSignIn?: boolean;
198
198
  }
199
+ declare const AuthProvider: React.FC<AuthProviderProps>;
200
+
201
+ interface AuthState extends AuthStore {
202
+ authProvider: IAuthProvider | null;
203
+ setAuthProvider: (provider: IAuthProvider) => void;
204
+ setSession: (session: AuthSession | null) => void;
205
+ }
206
+
207
+ declare const useAuth: () => AuthState;
199
208
 
200
209
  /**
201
210
  * Storage interface for cross-platform compatibility
@@ -284,15 +293,6 @@ declare class AuthProviderFactory {
284
293
  static getInstances(): Map<AuthProviderType, IAuthProvider>;
285
294
  }
286
295
 
287
- interface AuthProviderProps {
288
- children: ReactNode;
289
- providerType?: AuthProviderType;
290
- storage?: IAuthStorage;
291
- }
292
- declare const AuthProvider: ({ children, providerType, storage }: AuthProviderProps) => react_jsx_runtime.JSX.Element;
293
-
294
- declare const useAuth: () => AuthStore;
295
-
296
296
  type Database = {
297
297
  public: {
298
298
  Tables: {
@@ -344,4 +344,4 @@ declare function withAuth(request: NextRequest): {
344
344
 
345
345
  declare const createSupabaseServerClient: (cookieStore: ReadonlyRequestCookies) => _supabase_supabase_js.SupabaseClient<Database, "public", any>;
346
346
 
347
- export { type AuthConfig, AuthEvent, type AuthFormProps, type AuthMode, AuthProvider, AuthProviderFactory, type AuthSession, type AuthStore, type AuthStoreHook, type OAuthProvider$1 as OAuthProvider, type PasswordConfig, type User, type UserRole, createSupabaseServerClient, getSupabaseClient, useAuth, withAuth };
347
+ export { type AuthConfig, AuthEvent, type AuthFormProps, type AuthMode, AuthProvider, AuthProviderFactory, type AuthSession, type AuthStore, type OAuthProvider, type PasswordConfig, type User, type UserRole, createSupabaseServerClient, getSupabaseClient, useAuth, withAuth };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,91 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
1
+ import React from 'react';
3
2
  import * as _supabase_supabase_js from '@supabase/supabase-js';
4
3
  import { NextRequest, NextResponse } from 'next/server.js';
5
4
  import { ReadonlyRequestCookies } from 'next/dist/server/web/spec-extension/adapters/request-cookies';
6
5
 
6
+ /**
7
+ * OAuth provider types - re-export from types for backward compatibility
8
+ */
9
+ type OAuthProvider$1 = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
10
+ /**
11
+ * Authentication provider interface that abstracts authentication operations
12
+ * across different backends (Supabase, Firebase, etc.)
13
+ */
14
+ interface IAuthProvider {
15
+ /**
16
+ * Sign in with email and password
17
+ * @param email User's email address
18
+ * @param password User's password (required for email/password authentication)
19
+ * @returns Promise resolving to an object containing user, session, and error
20
+ */
21
+ signIn(email: string, password: string): Promise<{
22
+ user: User | null;
23
+ session: AuthSession | null;
24
+ error: any;
25
+ }>;
26
+ /**
27
+ * Sign up with email and password
28
+ * @param email User's email address
29
+ * @param password User's password (required for email/password authentication)
30
+ * @returns Promise resolving to an object containing user, session, and error
31
+ */
32
+ signUp(email: string, password: string): Promise<{
33
+ user: User | null;
34
+ session: AuthSession | null;
35
+ error: any;
36
+ }>;
37
+ /**
38
+ * Sign in with OAuth provider
39
+ * @param provider OAuth provider name
40
+ * @param redirectTo Optional redirect URL after authentication
41
+ * @returns Promise that resolves when OAuth flow is initiated
42
+ */
43
+ signInWithOAuth(provider: OAuthProvider$1, redirectTo?: string): Promise<void>;
44
+ /**
45
+ * Sign in with magic link (passwordless authentication)
46
+ * @param email User's email address
47
+ * @param redirectTo Optional redirect URL after email verification
48
+ * @returns Promise that resolves when magic link is sent
49
+ */
50
+ signInWithMagicLink(email: string, redirectTo?: string): Promise<void>;
51
+ /**
52
+ * Sign out the current user
53
+ * @returns Promise resolving to an object containing error
54
+ */
55
+ signOut(): Promise<{
56
+ error: any;
57
+ }>;
58
+ /**
59
+ * Get the current authenticated user
60
+ * @returns Promise resolving to the current user or null if not authenticated
61
+ */
62
+ getUser(): Promise<User | null>;
63
+ /**
64
+ * Get the current authentication session
65
+ * @returns Promise resolving to the current session or null if not authenticated
66
+ */
67
+ getSession(): Promise<AuthSession | null>;
68
+ /**
69
+ * Send password reset email
70
+ * @param email User's email address
71
+ * @returns Promise resolving to an object containing error
72
+ */
73
+ resetPassword(email: string): Promise<{
74
+ error: any;
75
+ }>;
76
+ /**
77
+ * Listen for authentication state changes
78
+ * @param callback Function called when auth state changes
79
+ * @returns Object containing subscription data for cleanup
80
+ */
81
+ onAuthStateChange(callback: (event: AuthEvent, session: AuthSession | null) => void): any;
82
+ /**
83
+ * Validate provider configuration
84
+ * @returns Promise that resolves if configuration is valid
85
+ */
86
+ validateConfiguration?(): Promise<void>;
87
+ }
88
+
7
89
  /**
8
90
  * User interface representing authenticated user data
9
91
  */
@@ -36,7 +118,7 @@ declare enum AuthEvent {
36
118
  /**
37
119
  * OAuth provider types supported by the auth system
38
120
  */
39
- type OAuthProvider$1 = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
121
+ type OAuthProvider = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
40
122
  /**
41
123
  * Authentication form modes
42
124
  */
@@ -83,119 +165,46 @@ interface AuthFormProps {
83
165
  onSuccess?: () => void;
84
166
  onError?: (error: Error) => void;
85
167
  redirectTo?: string;
86
- providers?: OAuthProvider$1[];
168
+ providers?: OAuthProvider[];
87
169
  allowMagicLink?: boolean;
88
170
  className?: string;
89
171
  }
90
- /**
91
- * Zustand store interface for authentication state and actions
92
- * This represents the actual store hook that components will use
93
- */
172
+
94
173
  interface AuthStore {
95
174
  user: User | null;
175
+ session: AuthSession | null;
96
176
  loading: boolean;
97
- error: string | null;
98
- updateUser: (user: User | null) => void;
177
+ error: Error | null;
178
+ setUser: (user: User | null) => void;
179
+ setSession: (session: AuthSession | null) => void;
99
180
  setLoading: (loading: boolean) => void;
100
- setError: (error: string | null) => void;
181
+ setError: (error: Error | null) => void;
182
+ setAuthProvider: (provider: IAuthProvider) => void;
101
183
  signIn: (email: string, password: string) => Promise<void>;
102
184
  signUp: (email: string, password: string) => Promise<void>;
103
185
  signOut: () => Promise<void>;
104
186
  resetPassword: (email: string) => Promise<void>;
105
- signInWithOAuth: (provider: OAuthProvider$1, redirectTo?: string) => Promise<void>;
187
+ signInWithOAuth: (provider: OAuthProvider, redirectTo?: string) => Promise<void>;
106
188
  signInWithMagicLink: (email: string, redirectTo?: string) => Promise<void>;
107
189
  getUser: () => Promise<User | null>;
108
190
  getSession: () => Promise<AuthSession | null>;
109
191
  onAuthStateChange: (callback: (event: AuthEvent, session: AuthSession | null) => void) => any;
110
192
  }
111
- /**
112
- * Type for the actual Zustand hook returned by createAuthStore
113
- * This is what gets passed through context and used by components
114
- */
115
- type AuthStoreHook = () => AuthStore;
116
193
 
117
- /**
118
- * OAuth provider types - re-export from types for backward compatibility
119
- */
120
- type OAuthProvider = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
121
- /**
122
- * Authentication provider interface that abstracts authentication operations
123
- * across different backends (Supabase, Firebase, etc.)
124
- */
125
- interface IAuthProvider {
126
- /**
127
- * Sign in with email and password
128
- * @param email User's email address
129
- * @param password User's password (required for email/password authentication)
130
- * @returns Promise resolving to an object containing user, session, and error
131
- */
132
- signIn(email: string, password: string): Promise<{
133
- user: User | null;
134
- session: AuthSession | null;
135
- error: any;
136
- }>;
137
- /**
138
- * Sign up with email and password
139
- * @param email User's email address
140
- * @param password User's password (required for email/password authentication)
141
- * @returns Promise resolving to an object containing user, session, and error
142
- */
143
- signUp(email: string, password: string): Promise<{
144
- user: User | null;
145
- session: AuthSession | null;
146
- error: any;
147
- }>;
148
- /**
149
- * Sign in with OAuth provider
150
- * @param provider OAuth provider name
151
- * @param redirectTo Optional redirect URL after authentication
152
- * @returns Promise that resolves when OAuth flow is initiated
153
- */
154
- signInWithOAuth(provider: OAuthProvider, redirectTo?: string): Promise<void>;
155
- /**
156
- * Sign in with magic link (passwordless authentication)
157
- * @param email User's email address
158
- * @param redirectTo Optional redirect URL after email verification
159
- * @returns Promise that resolves when magic link is sent
160
- */
161
- signInWithMagicLink(email: string, redirectTo?: string): Promise<void>;
162
- /**
163
- * Sign out the current user
164
- * @returns Promise resolving to an object containing error
165
- */
166
- signOut(): Promise<{
167
- error: any;
168
- }>;
169
- /**
170
- * Get the current authenticated user
171
- * @returns Promise resolving to the current user or null if not authenticated
172
- */
173
- getUser(): Promise<User | null>;
174
- /**
175
- * Get the current authentication session
176
- * @returns Promise resolving to the current session or null if not authenticated
177
- */
178
- getSession(): Promise<AuthSession | null>;
179
- /**
180
- * Send password reset email
181
- * @param email User's email address
182
- * @returns Promise resolving to an object containing error
183
- */
184
- resetPassword(email: string): Promise<{
185
- error: any;
186
- }>;
187
- /**
188
- * Listen for authentication state changes
189
- * @param callback Function called when auth state changes
190
- * @returns Object containing subscription data for cleanup
191
- */
192
- onAuthStateChange(callback: (event: AuthEvent, session: AuthSession | null) => void): any;
193
- /**
194
- * Validate provider configuration
195
- * @returns Promise that resolves if configuration is valid
196
- */
197
- validateConfiguration?(): Promise<void>;
194
+ interface AuthProviderProps {
195
+ children: React.ReactNode;
196
+ onAuthChange?: (event: AuthEvent) => void;
197
+ autoSignIn?: boolean;
198
198
  }
199
+ declare const AuthProvider: React.FC<AuthProviderProps>;
200
+
201
+ interface AuthState extends AuthStore {
202
+ authProvider: IAuthProvider | null;
203
+ setAuthProvider: (provider: IAuthProvider) => void;
204
+ setSession: (session: AuthSession | null) => void;
205
+ }
206
+
207
+ declare const useAuth: () => AuthState;
199
208
 
200
209
  /**
201
210
  * Storage interface for cross-platform compatibility
@@ -284,15 +293,6 @@ declare class AuthProviderFactory {
284
293
  static getInstances(): Map<AuthProviderType, IAuthProvider>;
285
294
  }
286
295
 
287
- interface AuthProviderProps {
288
- children: ReactNode;
289
- providerType?: AuthProviderType;
290
- storage?: IAuthStorage;
291
- }
292
- declare const AuthProvider: ({ children, providerType, storage }: AuthProviderProps) => react_jsx_runtime.JSX.Element;
293
-
294
- declare const useAuth: () => AuthStore;
295
-
296
296
  type Database = {
297
297
  public: {
298
298
  Tables: {
@@ -344,4 +344,4 @@ declare function withAuth(request: NextRequest): {
344
344
 
345
345
  declare const createSupabaseServerClient: (cookieStore: ReadonlyRequestCookies) => _supabase_supabase_js.SupabaseClient<Database, "public", any>;
346
346
 
347
- export { type AuthConfig, AuthEvent, type AuthFormProps, type AuthMode, AuthProvider, AuthProviderFactory, type AuthSession, type AuthStore, type AuthStoreHook, type OAuthProvider$1 as OAuthProvider, type PasswordConfig, type User, type UserRole, createSupabaseServerClient, getSupabaseClient, useAuth, withAuth };
347
+ export { type AuthConfig, AuthEvent, type AuthFormProps, type AuthMode, AuthProvider, AuthProviderFactory, type AuthSession, type AuthStore, type OAuthProvider, type PasswordConfig, type User, type UserRole, createSupabaseServerClient, getSupabaseClient, useAuth, withAuth };