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