@xouteiro/auth_npm 1.0.4 → 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 +48 -0
- package/dist/index.mjs +45 -0
- package/package.json +1 -1
- package/src/index.js +4 -1
- package/src/login.js +1 -1
- package/src/logout.js +18 -0
- package/src/register.js +29 -0
package/dist/index.js
CHANGED
@@ -2193,7 +2193,10 @@ var index_exports = {};
|
|
2193
2193
|
__export(index_exports, {
|
2194
2194
|
AuthWrapper: () => AuthWrapper,
|
2195
2195
|
LogoutButton: () => LogoutButton,
|
2196
|
+
initializeSupabase: () => initializeSupabase,
|
2196
2197
|
isAdmin: () => isAdmin,
|
2198
|
+
logout: () => logout,
|
2199
|
+
registerWithEmail: () => registerWithEmail,
|
2197
2200
|
signInWithEmail: () => signInWithEmail,
|
2198
2201
|
supabase: () => supabase,
|
2199
2202
|
useAuth: () => useAuth
|
@@ -2208,6 +2211,12 @@ var import_auth_ui_shared = require("@supabase/auth-ui-shared");
|
|
2208
2211
|
// src/supabaseClient.js
|
2209
2212
|
var import_supabase_js = require("@supabase/supabase-js");
|
2210
2213
|
var supabase = null;
|
2214
|
+
function initializeSupabase(url, anonKey) {
|
2215
|
+
if (!url || !anonKey) {
|
2216
|
+
throw new Error("Supabase URL and Anon Key are required to initialize the client.");
|
2217
|
+
}
|
2218
|
+
supabase = (0, import_supabase_js.createClient)(url, anonKey);
|
2219
|
+
}
|
2211
2220
|
|
2212
2221
|
// src/AuthWrapper.jsx
|
2213
2222
|
function AuthWrapper({ onAuth, providers = ["google", "github"], theme = "dark" }) {
|
@@ -2288,11 +2297,50 @@ async function signInWithEmail(email, password) {
|
|
2288
2297
|
return { session: null, error: err };
|
2289
2298
|
}
|
2290
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
|
+
}
|
2291
2336
|
// Annotate the CommonJS export names for ESM import in node:
|
2292
2337
|
0 && (module.exports = {
|
2293
2338
|
AuthWrapper,
|
2294
2339
|
LogoutButton,
|
2340
|
+
initializeSupabase,
|
2295
2341
|
isAdmin,
|
2342
|
+
logout,
|
2343
|
+
registerWithEmail,
|
2296
2344
|
signInWithEmail,
|
2297
2345
|
supabase,
|
2298
2346
|
useAuth
|
package/dist/index.mjs
CHANGED
@@ -2191,6 +2191,12 @@ import { ThemeSupa } from "@supabase/auth-ui-shared";
|
|
2191
2191
|
// src/supabaseClient.js
|
2192
2192
|
import { createClient } from "@supabase/supabase-js";
|
2193
2193
|
var supabase = null;
|
2194
|
+
function initializeSupabase(url, anonKey) {
|
2195
|
+
if (!url || !anonKey) {
|
2196
|
+
throw new Error("Supabase URL and Anon Key are required to initialize the client.");
|
2197
|
+
}
|
2198
|
+
supabase = createClient(url, anonKey);
|
2199
|
+
}
|
2194
2200
|
|
2195
2201
|
// src/AuthWrapper.jsx
|
2196
2202
|
function AuthWrapper({ onAuth, providers = ["google", "github"], theme = "dark" }) {
|
@@ -2271,10 +2277,49 @@ async function signInWithEmail(email, password) {
|
|
2271
2277
|
return { session: null, error: err };
|
2272
2278
|
}
|
2273
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
|
+
}
|
2274
2316
|
export {
|
2275
2317
|
AuthWrapper,
|
2276
2318
|
LogoutButton,
|
2319
|
+
initializeSupabase,
|
2277
2320
|
isAdmin,
|
2321
|
+
logout,
|
2322
|
+
registerWithEmail,
|
2278
2323
|
signInWithEmail,
|
2279
2324
|
supabase,
|
2280
2325
|
useAuth
|
package/package.json
CHANGED
package/src/index.js
CHANGED
@@ -3,4 +3,7 @@ export { default as LogoutButton } from './LogoutButton';
|
|
3
3
|
export { useAuth } from './useAuth';
|
4
4
|
export { isAdmin } from './utils';
|
5
5
|
export { supabase } from './supabaseClient';
|
6
|
-
export { signInWithEmail } from './login'; // Add this line
|
6
|
+
export { signInWithEmail } from './login'; // Add this line
|
7
|
+
export { initializeSupabase } from './supabaseClient';
|
8
|
+
export { registerWithEmail } from './register';
|
9
|
+
export { logout } from './logout';
|
package/src/login.js
CHANGED
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
|
+
}
|