@xouteiro/auth_npm 1.0.7 → 1.0.8
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 +282 -30
- package/dist/index.mjs +282 -30
- package/package.json +1 -1
- package/src/components/LoginOnly.jsx +81 -18
- package/src/components/LoginRegisterFlow.jsx +103 -9
- package/src/components/LogoutButton.jsx +50 -5
- package/src/components/RegisterOnly.jsx +97 -30
package/dist/index.js
CHANGED
@@ -2292,58 +2292,149 @@ async function logout() {
|
|
2292
2292
|
|
2293
2293
|
// src/components/LoginRegisterFlow.jsx
|
2294
2294
|
var import_react2 = __toESM(require_react());
|
2295
|
+
var boxStyle = {
|
2296
|
+
maxWidth: 380,
|
2297
|
+
margin: "40px auto",
|
2298
|
+
padding: 32,
|
2299
|
+
borderRadius: 14,
|
2300
|
+
boxShadow: "0 2px 16px rgba(0,0,0,0.09)",
|
2301
|
+
background: "#fff",
|
2302
|
+
fontFamily: "sans-serif"
|
2303
|
+
};
|
2304
|
+
var tabStyle = (active) => ({
|
2305
|
+
flex: 1,
|
2306
|
+
padding: 12,
|
2307
|
+
border: "none",
|
2308
|
+
borderBottom: active ? "3px solid #0070f3" : "3px solid #eee",
|
2309
|
+
background: "none",
|
2310
|
+
fontWeight: active ? 700 : 400,
|
2311
|
+
color: active ? "#0070f3" : "#444",
|
2312
|
+
cursor: "pointer",
|
2313
|
+
outline: "none"
|
2314
|
+
});
|
2315
|
+
var inputStyle = {
|
2316
|
+
width: "100%",
|
2317
|
+
padding: 10,
|
2318
|
+
margin: "10px 0",
|
2319
|
+
borderRadius: 6,
|
2320
|
+
border: "1px solid #ddd",
|
2321
|
+
fontSize: 16
|
2322
|
+
};
|
2323
|
+
var buttonStyle = {
|
2324
|
+
width: "100%",
|
2325
|
+
padding: 12,
|
2326
|
+
borderRadius: 6,
|
2327
|
+
border: "none",
|
2328
|
+
background: "#0070f3",
|
2329
|
+
color: "#fff",
|
2330
|
+
fontWeight: 600,
|
2331
|
+
fontSize: 16,
|
2332
|
+
marginTop: 10,
|
2333
|
+
cursor: "pointer"
|
2334
|
+
};
|
2335
|
+
var messageStyle = (success) => ({
|
2336
|
+
margin: "12px 0",
|
2337
|
+
color: success ? "#0a0" : "#d32f2f",
|
2338
|
+
background: success ? "#eafbe7" : "#fdeaea",
|
2339
|
+
padding: 8,
|
2340
|
+
borderRadius: 6,
|
2341
|
+
textAlign: "center",
|
2342
|
+
fontSize: 15
|
2343
|
+
});
|
2295
2344
|
function LoginRegisterFlow() {
|
2296
2345
|
const [mode, setMode] = (0, import_react2.useState)("login");
|
2297
2346
|
const [identifier, setIdentifier] = (0, import_react2.useState)("");
|
2298
2347
|
const [password, setPassword] = (0, import_react2.useState)("");
|
2299
2348
|
const [username, setUsername] = (0, import_react2.useState)("");
|
2300
2349
|
const [phone, setPhone] = (0, import_react2.useState)("");
|
2301
|
-
const [
|
2350
|
+
const [message, setMessage] = (0, import_react2.useState)(null);
|
2351
|
+
const [success, setSuccess] = (0, import_react2.useState)(false);
|
2352
|
+
const resetFields = () => {
|
2353
|
+
setIdentifier("");
|
2354
|
+
setPassword("");
|
2355
|
+
setUsername("");
|
2356
|
+
setPhone("");
|
2357
|
+
setMessage(null);
|
2358
|
+
setSuccess(false);
|
2359
|
+
};
|
2302
2360
|
const handleLogin = async (e) => {
|
2303
2361
|
e.preventDefault();
|
2304
|
-
|
2305
|
-
|
2362
|
+
setMessage(null);
|
2363
|
+
setSuccess(false);
|
2364
|
+
const { error } = await signInWithEmail(identifier, password);
|
2365
|
+
if (error) {
|
2366
|
+
setMessage(error.message || "Login failed");
|
2367
|
+
setSuccess(false);
|
2368
|
+
} else {
|
2369
|
+
setMessage("Login successful!");
|
2370
|
+
setSuccess(true);
|
2371
|
+
setTimeout(resetFields, 1200);
|
2372
|
+
}
|
2306
2373
|
};
|
2307
2374
|
const handleRegister = async (e) => {
|
2308
2375
|
e.preventDefault();
|
2309
|
-
|
2310
|
-
|
2376
|
+
setMessage(null);
|
2377
|
+
setSuccess(false);
|
2378
|
+
const { error } = await registerWithEmail(identifier, password, username, phone);
|
2379
|
+
if (error) {
|
2380
|
+
setMessage(error.message || "Registration failed");
|
2381
|
+
setSuccess(false);
|
2382
|
+
} else {
|
2383
|
+
setMessage("Registration successful! Please check your email to confirm.");
|
2384
|
+
setSuccess(true);
|
2385
|
+
setTimeout(resetFields, 2e3);
|
2386
|
+
}
|
2311
2387
|
};
|
2312
|
-
return /* @__PURE__ */ import_react2.default.createElement("div",
|
2388
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", { style: boxStyle }, /* @__PURE__ */ import_react2.default.createElement("div", { style: { display: "flex", marginBottom: 24 } }, /* @__PURE__ */ import_react2.default.createElement("button", { style: tabStyle(mode === "login"), onClick: () => {
|
2389
|
+
setMode("login");
|
2390
|
+
setMessage(null);
|
2391
|
+
} }, "Login"), /* @__PURE__ */ import_react2.default.createElement("button", { style: tabStyle(mode === "register"), onClick: () => {
|
2392
|
+
setMode("register");
|
2393
|
+
setMessage(null);
|
2394
|
+
} }, "Register")), mode === "login" ? /* @__PURE__ */ import_react2.default.createElement("form", { onSubmit: handleLogin }, /* @__PURE__ */ import_react2.default.createElement(
|
2313
2395
|
"input",
|
2314
2396
|
{
|
2397
|
+
style: inputStyle,
|
2315
2398
|
type: "text",
|
2316
2399
|
placeholder: "Email, phone, or username",
|
2317
2400
|
value: identifier,
|
2318
|
-
onChange: (e) => setIdentifier(e.target.value)
|
2401
|
+
onChange: (e) => setIdentifier(e.target.value),
|
2402
|
+
required: true
|
2319
2403
|
}
|
2320
2404
|
), /* @__PURE__ */ import_react2.default.createElement(
|
2321
2405
|
"input",
|
2322
2406
|
{
|
2407
|
+
style: inputStyle,
|
2323
2408
|
type: "password",
|
2324
2409
|
placeholder: "Password",
|
2325
2410
|
value: password,
|
2326
|
-
onChange: (e) => setPassword(e.target.value)
|
2411
|
+
onChange: (e) => setPassword(e.target.value),
|
2412
|
+
required: true
|
2327
2413
|
}
|
2328
|
-
), /* @__PURE__ */ import_react2.default.createElement("button", { type: "submit" }, "Login")) : /* @__PURE__ */ import_react2.default.createElement("form", { onSubmit: handleRegister }, /* @__PURE__ */ import_react2.default.createElement(
|
2414
|
+
), /* @__PURE__ */ import_react2.default.createElement("button", { style: buttonStyle, type: "submit" }, "Login")) : /* @__PURE__ */ import_react2.default.createElement("form", { onSubmit: handleRegister }, /* @__PURE__ */ import_react2.default.createElement(
|
2329
2415
|
"input",
|
2330
2416
|
{
|
2417
|
+
style: inputStyle,
|
2331
2418
|
type: "text",
|
2332
2419
|
placeholder: "Email",
|
2333
2420
|
value: identifier,
|
2334
|
-
onChange: (e) => setIdentifier(e.target.value)
|
2421
|
+
onChange: (e) => setIdentifier(e.target.value),
|
2422
|
+
required: true
|
2335
2423
|
}
|
2336
2424
|
), /* @__PURE__ */ import_react2.default.createElement(
|
2337
2425
|
"input",
|
2338
2426
|
{
|
2427
|
+
style: inputStyle,
|
2339
2428
|
type: "password",
|
2340
2429
|
placeholder: "Password",
|
2341
2430
|
value: password,
|
2342
|
-
onChange: (e) => setPassword(e.target.value)
|
2431
|
+
onChange: (e) => setPassword(e.target.value),
|
2432
|
+
required: true
|
2343
2433
|
}
|
2344
2434
|
), /* @__PURE__ */ import_react2.default.createElement(
|
2345
2435
|
"input",
|
2346
2436
|
{
|
2437
|
+
style: inputStyle,
|
2347
2438
|
type: "text",
|
2348
2439
|
placeholder: "Username (optional)",
|
2349
2440
|
value: username,
|
@@ -2352,76 +2443,194 @@ function LoginRegisterFlow() {
|
|
2352
2443
|
), /* @__PURE__ */ import_react2.default.createElement(
|
2353
2444
|
"input",
|
2354
2445
|
{
|
2446
|
+
style: inputStyle,
|
2355
2447
|
type: "text",
|
2356
2448
|
placeholder: "Phone (optional)",
|
2357
2449
|
value: phone,
|
2358
2450
|
onChange: (e) => setPhone(e.target.value)
|
2359
2451
|
}
|
2360
|
-
), /* @__PURE__ */ import_react2.default.createElement("button", { type: "submit" }, "Register")),
|
2452
|
+
), /* @__PURE__ */ import_react2.default.createElement("button", { style: buttonStyle, type: "submit" }, "Register")), message && /* @__PURE__ */ import_react2.default.createElement("div", { style: messageStyle(success) }, message));
|
2361
2453
|
}
|
2362
2454
|
|
2363
2455
|
// src/components/LoginOnly.jsx
|
2364
2456
|
var import_react3 = __toESM(require_react());
|
2457
|
+
var boxStyle2 = {
|
2458
|
+
maxWidth: 350,
|
2459
|
+
margin: "40px auto",
|
2460
|
+
padding: 28,
|
2461
|
+
borderRadius: 12,
|
2462
|
+
boxShadow: "0 2px 12px rgba(0,0,0,0.08)",
|
2463
|
+
background: "#fff",
|
2464
|
+
fontFamily: "sans-serif"
|
2465
|
+
};
|
2466
|
+
var inputStyle2 = {
|
2467
|
+
width: "100%",
|
2468
|
+
padding: 10,
|
2469
|
+
margin: "10px 0",
|
2470
|
+
borderRadius: 6,
|
2471
|
+
border: "1px solid #ddd",
|
2472
|
+
fontSize: 16
|
2473
|
+
};
|
2474
|
+
var buttonStyle2 = {
|
2475
|
+
width: "100%",
|
2476
|
+
padding: 12,
|
2477
|
+
borderRadius: 6,
|
2478
|
+
border: "none",
|
2479
|
+
background: "#0070f3",
|
2480
|
+
color: "#fff",
|
2481
|
+
fontWeight: 600,
|
2482
|
+
fontSize: 16,
|
2483
|
+
marginTop: 10,
|
2484
|
+
cursor: "pointer"
|
2485
|
+
};
|
2486
|
+
var messageStyle2 = (success) => ({
|
2487
|
+
margin: "12px 0",
|
2488
|
+
color: success ? "#0a0" : "#d32f2f",
|
2489
|
+
background: success ? "#eafbe7" : "#fdeaea",
|
2490
|
+
padding: 8,
|
2491
|
+
borderRadius: 6,
|
2492
|
+
textAlign: "center",
|
2493
|
+
fontSize: 15
|
2494
|
+
});
|
2365
2495
|
function LoginOnly() {
|
2366
2496
|
const [identifier, setIdentifier] = (0, import_react3.useState)("");
|
2367
2497
|
const [password, setPassword] = (0, import_react3.useState)("");
|
2368
|
-
const [
|
2498
|
+
const [message, setMessage] = (0, import_react3.useState)(null);
|
2499
|
+
const [success, setSuccess] = (0, import_react3.useState)(false);
|
2369
2500
|
const handleLogin = async (e) => {
|
2370
2501
|
e.preventDefault();
|
2371
|
-
|
2372
|
-
|
2502
|
+
setMessage(null);
|
2503
|
+
setSuccess(false);
|
2504
|
+
const { error } = await signInWithEmail(identifier, password);
|
2505
|
+
if (error) {
|
2506
|
+
setMessage(error.message || "Login failed");
|
2507
|
+
setSuccess(false);
|
2508
|
+
} else {
|
2509
|
+
setMessage("Login successful!");
|
2510
|
+
setSuccess(true);
|
2511
|
+
setTimeout(() => {
|
2512
|
+
setIdentifier("");
|
2513
|
+
setPassword("");
|
2514
|
+
setMessage(null);
|
2515
|
+
setSuccess(false);
|
2516
|
+
}, 1500);
|
2517
|
+
}
|
2373
2518
|
};
|
2374
|
-
return /* @__PURE__ */ import_react3.default.createElement("form", { onSubmit: handleLogin }, /* @__PURE__ */ import_react3.default.createElement(
|
2519
|
+
return /* @__PURE__ */ import_react3.default.createElement("div", { style: boxStyle2 }, /* @__PURE__ */ import_react3.default.createElement("form", { onSubmit: handleLogin }, /* @__PURE__ */ import_react3.default.createElement(
|
2375
2520
|
"input",
|
2376
2521
|
{
|
2522
|
+
style: inputStyle2,
|
2377
2523
|
type: "text",
|
2378
2524
|
placeholder: "Email, phone, or username",
|
2379
2525
|
value: identifier,
|
2380
|
-
onChange: (e) => setIdentifier(e.target.value)
|
2526
|
+
onChange: (e) => setIdentifier(e.target.value),
|
2527
|
+
required: true
|
2381
2528
|
}
|
2382
2529
|
), /* @__PURE__ */ import_react3.default.createElement(
|
2383
2530
|
"input",
|
2384
2531
|
{
|
2532
|
+
style: inputStyle2,
|
2385
2533
|
type: "password",
|
2386
2534
|
placeholder: "Password",
|
2387
2535
|
value: password,
|
2388
|
-
onChange: (e) => setPassword(e.target.value)
|
2536
|
+
onChange: (e) => setPassword(e.target.value),
|
2537
|
+
required: true
|
2389
2538
|
}
|
2390
|
-
), /* @__PURE__ */ import_react3.default.createElement("button", { type: "submit" }, "Login"),
|
2539
|
+
), /* @__PURE__ */ import_react3.default.createElement("button", { style: buttonStyle2, type: "submit" }, "Login")), message && /* @__PURE__ */ import_react3.default.createElement("div", { style: messageStyle2(success) }, message));
|
2391
2540
|
}
|
2392
2541
|
|
2393
2542
|
// src/components/RegisterOnly.jsx
|
2394
2543
|
var import_react4 = __toESM(require_react());
|
2544
|
+
var boxStyle3 = {
|
2545
|
+
maxWidth: 350,
|
2546
|
+
margin: "40px auto",
|
2547
|
+
padding: 28,
|
2548
|
+
borderRadius: 12,
|
2549
|
+
boxShadow: "0 2px 12px rgba(0,0,0,0.08)",
|
2550
|
+
background: "#fff",
|
2551
|
+
fontFamily: "sans-serif"
|
2552
|
+
};
|
2553
|
+
var inputStyle3 = {
|
2554
|
+
width: "100%",
|
2555
|
+
padding: 10,
|
2556
|
+
margin: "10px 0",
|
2557
|
+
borderRadius: 6,
|
2558
|
+
border: "1px solid #ddd",
|
2559
|
+
fontSize: 16
|
2560
|
+
};
|
2561
|
+
var buttonStyle3 = {
|
2562
|
+
width: "100%",
|
2563
|
+
padding: 12,
|
2564
|
+
borderRadius: 6,
|
2565
|
+
border: "none",
|
2566
|
+
background: "#0070f3",
|
2567
|
+
color: "#fff",
|
2568
|
+
fontWeight: 600,
|
2569
|
+
fontSize: 16,
|
2570
|
+
marginTop: 10,
|
2571
|
+
cursor: "pointer"
|
2572
|
+
};
|
2573
|
+
var messageStyle3 = (success) => ({
|
2574
|
+
margin: "12px 0",
|
2575
|
+
color: success ? "#0a0" : "#d32f2f",
|
2576
|
+
background: success ? "#eafbe7" : "#fdeaea",
|
2577
|
+
padding: 8,
|
2578
|
+
borderRadius: 6,
|
2579
|
+
textAlign: "center",
|
2580
|
+
fontSize: 15
|
2581
|
+
});
|
2395
2582
|
function RegisterOnly() {
|
2396
2583
|
const [email, setEmail] = (0, import_react4.useState)("");
|
2397
2584
|
const [password, setPassword] = (0, import_react4.useState)("");
|
2398
2585
|
const [username, setUsername] = (0, import_react4.useState)("");
|
2399
2586
|
const [phone, setPhone] = (0, import_react4.useState)("");
|
2400
|
-
const [
|
2587
|
+
const [message, setMessage] = (0, import_react4.useState)(null);
|
2588
|
+
const [success, setSuccess] = (0, import_react4.useState)(false);
|
2401
2589
|
const handleRegister = async (e) => {
|
2402
2590
|
e.preventDefault();
|
2403
|
-
|
2404
|
-
|
2591
|
+
setMessage(null);
|
2592
|
+
setSuccess(false);
|
2593
|
+
const { error } = await registerWithEmail(email, password, username, phone);
|
2594
|
+
if (error) {
|
2595
|
+
setMessage(error.message || "Registration failed");
|
2596
|
+
setSuccess(false);
|
2597
|
+
} else {
|
2598
|
+
setMessage("Registration successful! Please check your email to confirm.");
|
2599
|
+
setSuccess(true);
|
2600
|
+
setTimeout(() => {
|
2601
|
+
setEmail("");
|
2602
|
+
setPassword("");
|
2603
|
+
setUsername("");
|
2604
|
+
setPhone("");
|
2605
|
+
setMessage(null);
|
2606
|
+
setSuccess(false);
|
2607
|
+
}, 2e3);
|
2608
|
+
}
|
2405
2609
|
};
|
2406
|
-
return /* @__PURE__ */ import_react4.default.createElement("form", { onSubmit: handleRegister }, /* @__PURE__ */ import_react4.default.createElement(
|
2610
|
+
return /* @__PURE__ */ import_react4.default.createElement("div", { style: boxStyle3 }, /* @__PURE__ */ import_react4.default.createElement("form", { onSubmit: handleRegister }, /* @__PURE__ */ import_react4.default.createElement(
|
2407
2611
|
"input",
|
2408
2612
|
{
|
2613
|
+
style: inputStyle3,
|
2409
2614
|
type: "text",
|
2410
2615
|
placeholder: "Email",
|
2411
2616
|
value: email,
|
2412
|
-
onChange: (e) => setEmail(e.target.value)
|
2617
|
+
onChange: (e) => setEmail(e.target.value),
|
2618
|
+
required: true
|
2413
2619
|
}
|
2414
2620
|
), /* @__PURE__ */ import_react4.default.createElement(
|
2415
2621
|
"input",
|
2416
2622
|
{
|
2623
|
+
style: inputStyle3,
|
2417
2624
|
type: "password",
|
2418
2625
|
placeholder: "Password",
|
2419
2626
|
value: password,
|
2420
|
-
onChange: (e) => setPassword(e.target.value)
|
2627
|
+
onChange: (e) => setPassword(e.target.value),
|
2628
|
+
required: true
|
2421
2629
|
}
|
2422
2630
|
), /* @__PURE__ */ import_react4.default.createElement(
|
2423
2631
|
"input",
|
2424
2632
|
{
|
2633
|
+
style: inputStyle3,
|
2425
2634
|
type: "text",
|
2426
2635
|
placeholder: "Username (optional)",
|
2427
2636
|
value: username,
|
@@ -2430,23 +2639,66 @@ function RegisterOnly() {
|
|
2430
2639
|
), /* @__PURE__ */ import_react4.default.createElement(
|
2431
2640
|
"input",
|
2432
2641
|
{
|
2642
|
+
style: inputStyle3,
|
2433
2643
|
type: "text",
|
2434
2644
|
placeholder: "Phone (optional)",
|
2435
2645
|
value: phone,
|
2436
2646
|
onChange: (e) => setPhone(e.target.value)
|
2437
2647
|
}
|
2438
|
-
), /* @__PURE__ */ import_react4.default.createElement("button", { type: "submit" }, "Register"),
|
2648
|
+
), /* @__PURE__ */ import_react4.default.createElement("button", { style: buttonStyle3, type: "submit" }, "Register")), message && /* @__PURE__ */ import_react4.default.createElement("div", { style: messageStyle3(success) }, message));
|
2439
2649
|
}
|
2440
2650
|
|
2441
2651
|
// src/components/LogoutButton.jsx
|
2442
2652
|
var import_react5 = __toESM(require_react());
|
2653
|
+
var boxStyle4 = {
|
2654
|
+
maxWidth: 350,
|
2655
|
+
margin: "24px auto",
|
2656
|
+
padding: 20,
|
2657
|
+
borderRadius: 10,
|
2658
|
+
boxShadow: "0 2px 12px rgba(0,0,0,0.08)",
|
2659
|
+
background: "#fff",
|
2660
|
+
fontFamily: "sans-serif",
|
2661
|
+
textAlign: "center"
|
2662
|
+
};
|
2663
|
+
var buttonStyle4 = {
|
2664
|
+
padding: "10px 28px",
|
2665
|
+
borderRadius: 6,
|
2666
|
+
border: "none",
|
2667
|
+
background: "#0070f3",
|
2668
|
+
color: "#fff",
|
2669
|
+
fontWeight: 600,
|
2670
|
+
fontSize: 16,
|
2671
|
+
cursor: "pointer"
|
2672
|
+
};
|
2673
|
+
var messageStyle4 = (success) => ({
|
2674
|
+
margin: "12px 0",
|
2675
|
+
color: success ? "#0a0" : "#d32f2f",
|
2676
|
+
background: success ? "#eafbe7" : "#fdeaea",
|
2677
|
+
padding: 8,
|
2678
|
+
borderRadius: 6,
|
2679
|
+
textAlign: "center",
|
2680
|
+
fontSize: 15
|
2681
|
+
});
|
2443
2682
|
function LogoutButton() {
|
2444
|
-
const [
|
2683
|
+
const [message, setMessage] = (0, import_react5.useState)(null);
|
2684
|
+
const [success, setSuccess] = (0, import_react5.useState)(false);
|
2445
2685
|
const handleLogout = async () => {
|
2446
|
-
|
2447
|
-
|
2686
|
+
setMessage(null);
|
2687
|
+
setSuccess(false);
|
2688
|
+
const { error } = await logout();
|
2689
|
+
if (error) {
|
2690
|
+
setMessage(error.message || "Logout failed");
|
2691
|
+
setSuccess(false);
|
2692
|
+
} else {
|
2693
|
+
setMessage("Logout successful!");
|
2694
|
+
setSuccess(true);
|
2695
|
+
setTimeout(() => {
|
2696
|
+
setMessage(null);
|
2697
|
+
setSuccess(false);
|
2698
|
+
}, 1500);
|
2699
|
+
}
|
2448
2700
|
};
|
2449
|
-
return /* @__PURE__ */ import_react5.default.createElement("div",
|
2701
|
+
return /* @__PURE__ */ import_react5.default.createElement("div", { style: boxStyle4 }, /* @__PURE__ */ import_react5.default.createElement("button", { style: buttonStyle4, onClick: handleLogout }, "Logout"), message && /* @__PURE__ */ import_react5.default.createElement("div", { style: messageStyle4(success) }, message));
|
2450
2702
|
}
|
2451
2703
|
// Annotate the CommonJS export names for ESM import in node:
|
2452
2704
|
0 && (module.exports = {
|