@digilogiclabs/saas-factory-auth 0.4.2 → 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
@@ -3,6 +3,89 @@ import * as _supabase_supabase_js from '@supabase/supabase-js';
3
3
  import { NextRequest, NextResponse } from 'next/server.js';
4
4
  import { ReadonlyRequestCookies } from 'next/dist/server/web/spec-extension/adapters/request-cookies';
5
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
+
6
89
  /**
7
90
  * User interface representing authenticated user data
8
91
  */
@@ -35,7 +118,7 @@ declare enum AuthEvent {
35
118
  /**
36
119
  * OAuth provider types supported by the auth system
37
120
  */
38
- type OAuthProvider$1 = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
121
+ type OAuthProvider = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
39
122
  /**
40
123
  * Authentication form modes
41
124
  */
@@ -82,7 +165,7 @@ interface AuthFormProps {
82
165
  onSuccess?: () => void;
83
166
  onError?: (error: Error) => void;
84
167
  redirectTo?: string;
85
- providers?: OAuthProvider$1[];
168
+ providers?: OAuthProvider[];
86
169
  allowMagicLink?: boolean;
87
170
  className?: string;
88
171
  }
@@ -101,96 +184,13 @@ interface AuthStore {
101
184
  signUp: (email: string, password: string) => Promise<void>;
102
185
  signOut: () => Promise<void>;
103
186
  resetPassword: (email: string) => Promise<void>;
104
- signInWithOAuth: (provider: OAuthProvider$1, redirectTo?: string) => Promise<void>;
187
+ signInWithOAuth: (provider: OAuthProvider, redirectTo?: string) => Promise<void>;
105
188
  signInWithMagicLink: (email: string, redirectTo?: string) => Promise<void>;
106
189
  getUser: () => Promise<User | null>;
107
190
  getSession: () => Promise<AuthSession | null>;
108
191
  onAuthStateChange: (callback: (event: AuthEvent, session: AuthSession | null) => void) => any;
109
192
  }
110
193
 
111
- /**
112
- * OAuth provider types - re-export from types for backward compatibility
113
- */
114
- type OAuthProvider = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
115
- /**
116
- * Authentication provider interface that abstracts authentication operations
117
- * across different backends (Supabase, Firebase, etc.)
118
- */
119
- interface IAuthProvider {
120
- /**
121
- * Sign in with email and password
122
- * @param email User's email address
123
- * @param password User's password (required for email/password authentication)
124
- * @returns Promise resolving to an object containing user, session, and error
125
- */
126
- signIn(email: string, password: string): Promise<{
127
- user: User | null;
128
- session: AuthSession | null;
129
- error: any;
130
- }>;
131
- /**
132
- * Sign up with email and password
133
- * @param email User's email address
134
- * @param password User's password (required for email/password authentication)
135
- * @returns Promise resolving to an object containing user, session, and error
136
- */
137
- signUp(email: string, password: string): Promise<{
138
- user: User | null;
139
- session: AuthSession | null;
140
- error: any;
141
- }>;
142
- /**
143
- * Sign in with OAuth provider
144
- * @param provider OAuth provider name
145
- * @param redirectTo Optional redirect URL after authentication
146
- * @returns Promise that resolves when OAuth flow is initiated
147
- */
148
- signInWithOAuth(provider: OAuthProvider, redirectTo?: string): Promise<void>;
149
- /**
150
- * Sign in with magic link (passwordless authentication)
151
- * @param email User's email address
152
- * @param redirectTo Optional redirect URL after email verification
153
- * @returns Promise that resolves when magic link is sent
154
- */
155
- signInWithMagicLink(email: string, redirectTo?: string): Promise<void>;
156
- /**
157
- * Sign out the current user
158
- * @returns Promise resolving to an object containing error
159
- */
160
- signOut(): Promise<{
161
- error: any;
162
- }>;
163
- /**
164
- * Get the current authenticated user
165
- * @returns Promise resolving to the current user or null if not authenticated
166
- */
167
- getUser(): Promise<User | null>;
168
- /**
169
- * Get the current authentication session
170
- * @returns Promise resolving to the current session or null if not authenticated
171
- */
172
- getSession(): Promise<AuthSession | null>;
173
- /**
174
- * Send password reset email
175
- * @param email User's email address
176
- * @returns Promise resolving to an object containing error
177
- */
178
- resetPassword(email: string): Promise<{
179
- error: any;
180
- }>;
181
- /**
182
- * Listen for authentication state changes
183
- * @param callback Function called when auth state changes
184
- * @returns Object containing subscription data for cleanup
185
- */
186
- onAuthStateChange(callback: (event: AuthEvent, session: AuthSession | null) => void): any;
187
- /**
188
- * Validate provider configuration
189
- * @returns Promise that resolves if configuration is valid
190
- */
191
- validateConfiguration?(): Promise<void>;
192
- }
193
-
194
194
  interface AuthProviderProps {
195
195
  children: React.ReactNode;
196
196
  onAuthChange?: (event: AuthEvent) => void;
@@ -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 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
@@ -3,6 +3,89 @@ import * as _supabase_supabase_js from '@supabase/supabase-js';
3
3
  import { NextRequest, NextResponse } from 'next/server.js';
4
4
  import { ReadonlyRequestCookies } from 'next/dist/server/web/spec-extension/adapters/request-cookies';
5
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
+
6
89
  /**
7
90
  * User interface representing authenticated user data
8
91
  */
@@ -35,7 +118,7 @@ declare enum AuthEvent {
35
118
  /**
36
119
  * OAuth provider types supported by the auth system
37
120
  */
38
- type OAuthProvider$1 = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
121
+ type OAuthProvider = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
39
122
  /**
40
123
  * Authentication form modes
41
124
  */
@@ -82,7 +165,7 @@ interface AuthFormProps {
82
165
  onSuccess?: () => void;
83
166
  onError?: (error: Error) => void;
84
167
  redirectTo?: string;
85
- providers?: OAuthProvider$1[];
168
+ providers?: OAuthProvider[];
86
169
  allowMagicLink?: boolean;
87
170
  className?: string;
88
171
  }
@@ -101,96 +184,13 @@ interface AuthStore {
101
184
  signUp: (email: string, password: string) => Promise<void>;
102
185
  signOut: () => Promise<void>;
103
186
  resetPassword: (email: string) => Promise<void>;
104
- signInWithOAuth: (provider: OAuthProvider$1, redirectTo?: string) => Promise<void>;
187
+ signInWithOAuth: (provider: OAuthProvider, redirectTo?: string) => Promise<void>;
105
188
  signInWithMagicLink: (email: string, redirectTo?: string) => Promise<void>;
106
189
  getUser: () => Promise<User | null>;
107
190
  getSession: () => Promise<AuthSession | null>;
108
191
  onAuthStateChange: (callback: (event: AuthEvent, session: AuthSession | null) => void) => any;
109
192
  }
110
193
 
111
- /**
112
- * OAuth provider types - re-export from types for backward compatibility
113
- */
114
- type OAuthProvider = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
115
- /**
116
- * Authentication provider interface that abstracts authentication operations
117
- * across different backends (Supabase, Firebase, etc.)
118
- */
119
- interface IAuthProvider {
120
- /**
121
- * Sign in with email and password
122
- * @param email User's email address
123
- * @param password User's password (required for email/password authentication)
124
- * @returns Promise resolving to an object containing user, session, and error
125
- */
126
- signIn(email: string, password: string): Promise<{
127
- user: User | null;
128
- session: AuthSession | null;
129
- error: any;
130
- }>;
131
- /**
132
- * Sign up with email and password
133
- * @param email User's email address
134
- * @param password User's password (required for email/password authentication)
135
- * @returns Promise resolving to an object containing user, session, and error
136
- */
137
- signUp(email: string, password: string): Promise<{
138
- user: User | null;
139
- session: AuthSession | null;
140
- error: any;
141
- }>;
142
- /**
143
- * Sign in with OAuth provider
144
- * @param provider OAuth provider name
145
- * @param redirectTo Optional redirect URL after authentication
146
- * @returns Promise that resolves when OAuth flow is initiated
147
- */
148
- signInWithOAuth(provider: OAuthProvider, redirectTo?: string): Promise<void>;
149
- /**
150
- * Sign in with magic link (passwordless authentication)
151
- * @param email User's email address
152
- * @param redirectTo Optional redirect URL after email verification
153
- * @returns Promise that resolves when magic link is sent
154
- */
155
- signInWithMagicLink(email: string, redirectTo?: string): Promise<void>;
156
- /**
157
- * Sign out the current user
158
- * @returns Promise resolving to an object containing error
159
- */
160
- signOut(): Promise<{
161
- error: any;
162
- }>;
163
- /**
164
- * Get the current authenticated user
165
- * @returns Promise resolving to the current user or null if not authenticated
166
- */
167
- getUser(): Promise<User | null>;
168
- /**
169
- * Get the current authentication session
170
- * @returns Promise resolving to the current session or null if not authenticated
171
- */
172
- getSession(): Promise<AuthSession | null>;
173
- /**
174
- * Send password reset email
175
- * @param email User's email address
176
- * @returns Promise resolving to an object containing error
177
- */
178
- resetPassword(email: string): Promise<{
179
- error: any;
180
- }>;
181
- /**
182
- * Listen for authentication state changes
183
- * @param callback Function called when auth state changes
184
- * @returns Object containing subscription data for cleanup
185
- */
186
- onAuthStateChange(callback: (event: AuthEvent, session: AuthSession | null) => void): any;
187
- /**
188
- * Validate provider configuration
189
- * @returns Promise that resolves if configuration is valid
190
- */
191
- validateConfiguration?(): Promise<void>;
192
- }
193
-
194
194
  interface AuthProviderProps {
195
195
  children: React.ReactNode;
196
196
  onAuthChange?: (event: AuthEvent) => void;
@@ -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 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.js CHANGED
@@ -1082,7 +1082,7 @@ var AuthProvider = ({
1082
1082
  const setSession = useAuthStore((state) => state.setSession);
1083
1083
  const setLoading = useAuthStore((state) => state.setLoading);
1084
1084
  const setError = useAuthStore((state) => state.setError);
1085
- const setAuthProviderInStore = useAuthStore((state) => state.setAuthProvider);
1085
+ const setAuthProvider = useAuthStore((state) => state.setAuthProvider);
1086
1086
  react.useEffect(() => {
1087
1087
  let mounted = true;
1088
1088
  const initializeAuth = async () => {
@@ -1093,7 +1093,7 @@ var AuthProvider = ({
1093
1093
  });
1094
1094
  if (!mounted) return;
1095
1095
  authProviderRef.current = provider;
1096
- setAuthProviderInStore(provider);
1096
+ setAuthProvider(provider);
1097
1097
  const { data } = provider.onAuthStateChange((event, session) => {
1098
1098
  if (!mounted) return;
1099
1099
  if (session) {
@@ -1117,19 +1117,27 @@ var AuthProvider = ({
1117
1117
  if (autoSignIn) {
1118
1118
  try {
1119
1119
  const currentSession = await provider.getSession();
1120
- if (mounted && currentSession) {
1121
- setUser(currentSession.user);
1122
- setSession(currentSession);
1120
+ if (mounted) {
1121
+ if (currentSession) {
1122
+ setUser(currentSession.user);
1123
+ setSession(currentSession);
1124
+ } else {
1125
+ setUser(null);
1126
+ setSession(null);
1127
+ }
1128
+ setLoading(false);
1123
1129
  }
1124
1130
  } catch (error) {
1125
1131
  console.error("Failed to get initial session:", error);
1126
1132
  if (mounted) {
1127
1133
  setError(error instanceof Error ? error : new Error("Failed to get session"));
1134
+ setLoading(false);
1128
1135
  }
1129
1136
  }
1130
- }
1131
- if (mounted) {
1132
- setLoading(false);
1137
+ } else {
1138
+ if (mounted) {
1139
+ setLoading(false);
1140
+ }
1133
1141
  }
1134
1142
  } catch (error) {
1135
1143
  console.error("Failed to initialize auth provider:", error);
@@ -1154,6 +1162,11 @@ var AuthProvider = ({
1154
1162
  // src/hooks/useAuth.ts
1155
1163
  var useAuth = () => {
1156
1164
  const authState = useAuthStore();
1165
+ if (!authState.authProvider && !authState.loading) {
1166
+ console.warn(
1167
+ "Auth provider not initialized. Make sure to wrap your app with <AuthProvider> component."
1168
+ );
1169
+ }
1157
1170
  return authState;
1158
1171
  };
1159
1172
  var createClient2 = () => {