@xouteiro/auth_npm 1.0.5 → 1.0.6
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.js +40 -0
- package/dist/index.mjs +38 -0
- package/package.json +1 -1
- package/src/index.js +3 -1
- package/src/logout.js +18 -0
- package/src/register.js +29 -0
package/dist/index.js
CHANGED
@@ -2195,6 +2195,8 @@ __export(index_exports, {
|
|
2195
2195
|
LogoutButton: () => LogoutButton,
|
2196
2196
|
initializeSupabase: () => initializeSupabase,
|
2197
2197
|
isAdmin: () => isAdmin,
|
2198
|
+
logout: () => logout,
|
2199
|
+
registerWithEmail: () => registerWithEmail,
|
2198
2200
|
signInWithEmail: () => signInWithEmail,
|
2199
2201
|
supabase: () => supabase,
|
2200
2202
|
useAuth: () => useAuth
|
@@ -2295,12 +2297,50 @@ async function signInWithEmail(email, password) {
|
|
2295
2297
|
return { session: null, error: err };
|
2296
2298
|
}
|
2297
2299
|
}
|
2300
|
+
|
2301
|
+
// src/register.js
|
2302
|
+
async function registerWithEmail(email, password, username, phone) {
|
2303
|
+
try {
|
2304
|
+
const { data: user, error } = await supabase.auth.signUp({
|
2305
|
+
email,
|
2306
|
+
password,
|
2307
|
+
options: {
|
2308
|
+
data: {
|
2309
|
+
username,
|
2310
|
+
// Store the display name
|
2311
|
+
phone
|
2312
|
+
// Store the phone number
|
2313
|
+
}
|
2314
|
+
}
|
2315
|
+
});
|
2316
|
+
return { user, error };
|
2317
|
+
} catch (err) {
|
2318
|
+
console.error("Unexpected error during registration:", err);
|
2319
|
+
return { user: null, error: err };
|
2320
|
+
}
|
2321
|
+
}
|
2322
|
+
|
2323
|
+
// src/logout.js
|
2324
|
+
async function logout() {
|
2325
|
+
try {
|
2326
|
+
const { error } = await supabase.auth.signOut();
|
2327
|
+
if (error) {
|
2328
|
+
console.error("Error during logout:", error);
|
2329
|
+
}
|
2330
|
+
return { error };
|
2331
|
+
} catch (err) {
|
2332
|
+
console.error("Unexpected error during logout:", err);
|
2333
|
+
return { error: err };
|
2334
|
+
}
|
2335
|
+
}
|
2298
2336
|
// Annotate the CommonJS export names for ESM import in node:
|
2299
2337
|
0 && (module.exports = {
|
2300
2338
|
AuthWrapper,
|
2301
2339
|
LogoutButton,
|
2302
2340
|
initializeSupabase,
|
2303
2341
|
isAdmin,
|
2342
|
+
logout,
|
2343
|
+
registerWithEmail,
|
2304
2344
|
signInWithEmail,
|
2305
2345
|
supabase,
|
2306
2346
|
useAuth
|
package/dist/index.mjs
CHANGED
@@ -2277,11 +2277,49 @@ async function signInWithEmail(email, password) {
|
|
2277
2277
|
return { session: null, error: err };
|
2278
2278
|
}
|
2279
2279
|
}
|
2280
|
+
|
2281
|
+
// src/register.js
|
2282
|
+
async function registerWithEmail(email, password, username, phone) {
|
2283
|
+
try {
|
2284
|
+
const { data: user, error } = await supabase.auth.signUp({
|
2285
|
+
email,
|
2286
|
+
password,
|
2287
|
+
options: {
|
2288
|
+
data: {
|
2289
|
+
username,
|
2290
|
+
// Store the display name
|
2291
|
+
phone
|
2292
|
+
// Store the phone number
|
2293
|
+
}
|
2294
|
+
}
|
2295
|
+
});
|
2296
|
+
return { user, error };
|
2297
|
+
} catch (err) {
|
2298
|
+
console.error("Unexpected error during registration:", err);
|
2299
|
+
return { user: null, error: err };
|
2300
|
+
}
|
2301
|
+
}
|
2302
|
+
|
2303
|
+
// src/logout.js
|
2304
|
+
async function logout() {
|
2305
|
+
try {
|
2306
|
+
const { error } = await supabase.auth.signOut();
|
2307
|
+
if (error) {
|
2308
|
+
console.error("Error during logout:", error);
|
2309
|
+
}
|
2310
|
+
return { error };
|
2311
|
+
} catch (err) {
|
2312
|
+
console.error("Unexpected error during logout:", err);
|
2313
|
+
return { error: err };
|
2314
|
+
}
|
2315
|
+
}
|
2280
2316
|
export {
|
2281
2317
|
AuthWrapper,
|
2282
2318
|
LogoutButton,
|
2283
2319
|
initializeSupabase,
|
2284
2320
|
isAdmin,
|
2321
|
+
logout,
|
2322
|
+
registerWithEmail,
|
2285
2323
|
signInWithEmail,
|
2286
2324
|
supabase,
|
2287
2325
|
useAuth
|
package/package.json
CHANGED
package/src/index.js
CHANGED
@@ -4,4 +4,6 @@ export { useAuth } from './useAuth';
|
|
4
4
|
export { isAdmin } from './utils';
|
5
5
|
export { supabase } from './supabaseClient';
|
6
6
|
export { signInWithEmail } from './login'; // Add this line
|
7
|
-
export { initializeSupabase } from './supabaseClient';
|
7
|
+
export { initializeSupabase } from './supabaseClient';
|
8
|
+
export { registerWithEmail } from './register';
|
9
|
+
export { logout } from './logout';
|
package/src/logout.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
import { supabase } from './supabaseClient';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Logs out the currently authenticated user.
|
5
|
+
* @returns {Promise<{ error: any }>} - The error (if any) during logout.
|
6
|
+
*/
|
7
|
+
export async function logout() {
|
8
|
+
try {
|
9
|
+
const { error } = await supabase.auth.signOut();
|
10
|
+
if (error) {
|
11
|
+
console.error('Error during logout:', error);
|
12
|
+
}
|
13
|
+
return { error };
|
14
|
+
} catch (err) {
|
15
|
+
console.error('Unexpected error during logout:', err);
|
16
|
+
return { error: err };
|
17
|
+
}
|
18
|
+
}
|
package/src/register.js
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
import { supabase } from './supabaseClient';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Registers a new user using email, password, and optional username and phone number.
|
5
|
+
* @param {string} email - The user's email address.
|
6
|
+
* @param {string} password - The user's password.
|
7
|
+
* @param {string} [username] - The user's display name (optional).
|
8
|
+
* @param {string} [phone] - The user's phone number (optional).
|
9
|
+
* @returns {Promise<{ user: any, error: any }>} - The user and error (if any).
|
10
|
+
*/
|
11
|
+
export async function registerWithEmail(email, password, username, phone) {
|
12
|
+
try {
|
13
|
+
const { data: user, error } = await supabase.auth.signUp({
|
14
|
+
email,
|
15
|
+
password,
|
16
|
+
options: {
|
17
|
+
data: {
|
18
|
+
username, // Store the display name
|
19
|
+
phone, // Store the phone number
|
20
|
+
},
|
21
|
+
},
|
22
|
+
});
|
23
|
+
|
24
|
+
return { user, error };
|
25
|
+
} catch (err) {
|
26
|
+
console.error('Unexpected error during registration:', err);
|
27
|
+
return { user: null, error: err };
|
28
|
+
}
|
29
|
+
}
|