@xouteiro/auth_npm 1.0.6 → 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.mjs CHANGED
@@ -1356,7 +1356,7 @@ var require_react_development = __commonJS({
1356
1356
  }
1357
1357
  return dispatcher.useContext(Context);
1358
1358
  }
1359
- function useState3(initialState) {
1359
+ function useState6(initialState) {
1360
1360
  var dispatcher = resolveDispatcher();
1361
1361
  return dispatcher.useState(initialState);
1362
1362
  }
@@ -1368,7 +1368,7 @@ var require_react_development = __commonJS({
1368
1368
  var dispatcher = resolveDispatcher();
1369
1369
  return dispatcher.useRef(initialValue);
1370
1370
  }
1371
- function useEffect3(create, deps) {
1371
+ function useEffect2(create, deps) {
1372
1372
  var dispatcher = resolveDispatcher();
1373
1373
  return dispatcher.useEffect(create, deps);
1374
1374
  }
@@ -2151,7 +2151,7 @@ var require_react_development = __commonJS({
2151
2151
  exports.useContext = useContext;
2152
2152
  exports.useDebugValue = useDebugValue;
2153
2153
  exports.useDeferredValue = useDeferredValue;
2154
- exports.useEffect = useEffect3;
2154
+ exports.useEffect = useEffect2;
2155
2155
  exports.useId = useId;
2156
2156
  exports.useImperativeHandle = useImperativeHandle;
2157
2157
  exports.useInsertionEffect = useInsertionEffect;
@@ -2159,7 +2159,7 @@ var require_react_development = __commonJS({
2159
2159
  exports.useMemo = useMemo;
2160
2160
  exports.useReducer = useReducer;
2161
2161
  exports.useRef = useRef;
2162
- exports.useState = useState3;
2162
+ exports.useState = useState6;
2163
2163
  exports.useSyncExternalStore = useSyncExternalStore;
2164
2164
  exports.useTransition = useTransition;
2165
2165
  exports.version = ReactVersion;
@@ -2183,57 +2183,11 @@ var require_react = __commonJS({
2183
2183
  }
2184
2184
  });
2185
2185
 
2186
- // src/AuthWrapper.jsx
2186
+ // src/useAuth.js
2187
2187
  var import_react = __toESM(require_react());
2188
- import { Auth } from "@supabase/auth-ui-react";
2189
- import { ThemeSupa } from "@supabase/auth-ui-shared";
2190
-
2191
- // src/supabaseClient.js
2192
- import { createClient } from "@supabase/supabase-js";
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
- }
2200
-
2201
- // src/AuthWrapper.jsx
2202
- function AuthWrapper({ onAuth, providers = ["google", "github"], theme = "dark" }) {
2203
- if (!supabase) {
2204
- throw new Error("Supabase client is not initialized. Call initializeSupabase() before using AuthWrapper.");
2205
- }
2188
+ function useAuth(supabaseClient) {
2206
2189
  const [session, setSession] = (0, import_react.useState)(null);
2207
2190
  (0, import_react.useEffect)(() => {
2208
- supabase.auth.getSession().then(({ data: { session: session2 } }) => {
2209
- setSession(session2);
2210
- if (session2) onAuth == null ? void 0 : onAuth(session2);
2211
- });
2212
- const { data: subscription } = supabase.auth.onAuthStateChange((_event, session2) => {
2213
- setSession(session2);
2214
- if (session2) onAuth == null ? void 0 : onAuth(session2);
2215
- });
2216
- return () => subscription == null ? void 0 : subscription.unsubscribe();
2217
- }, [onAuth]);
2218
- if (!session) {
2219
- return /* @__PURE__ */ React.createElement(
2220
- Auth,
2221
- {
2222
- supabaseClient: supabase,
2223
- appearance: { theme: ThemeSupa },
2224
- providers,
2225
- theme
2226
- }
2227
- );
2228
- }
2229
- return /* @__PURE__ */ React.createElement("div", null, "\u2705 Logged in as: ", session.user.email);
2230
- }
2231
-
2232
- // src/useAuth.js
2233
- var import_react2 = __toESM(require_react());
2234
- function useAuth(supabaseClient) {
2235
- const [session, setSession] = (0, import_react2.useState)(null);
2236
- (0, import_react2.useEffect)(() => {
2237
2191
  supabaseClient.auth.getSession().then(({ data: { session: session2 } }) => {
2238
2192
  setSession(session2);
2239
2193
  });
@@ -2249,21 +2203,21 @@ function useAuth(supabaseClient) {
2249
2203
  return { session, signOut };
2250
2204
  }
2251
2205
 
2252
- // src/LogoutButton.jsx
2253
- function LogoutButton({ supabaseClient, onLogout }) {
2254
- const { signOut } = useAuth(supabaseClient);
2255
- const handleLogout = async () => {
2256
- await signOut();
2257
- onLogout == null ? void 0 : onLogout();
2258
- };
2259
- return /* @__PURE__ */ React.createElement("button", { onClick: handleLogout }, "\u{1F6AA} Log out");
2260
- }
2261
-
2262
2206
  // src/utils.js
2263
2207
  function isAdmin(user) {
2264
2208
  return (user == null ? void 0 : user.role) === "admin";
2265
2209
  }
2266
2210
 
2211
+ // src/supabaseClient.js
2212
+ import { createClient } from "@supabase/supabase-js";
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 = createClient(url, anonKey);
2219
+ }
2220
+
2267
2221
  // src/login.js
2268
2222
  async function signInWithEmail(email, password) {
2269
2223
  try {
@@ -2313,9 +2267,422 @@ async function logout() {
2313
2267
  return { error: err };
2314
2268
  }
2315
2269
  }
2270
+
2271
+ // src/components/LoginRegisterFlow.jsx
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
+ });
2322
+ function LoginRegisterFlow() {
2323
+ const [mode, setMode] = (0, import_react2.useState)("login");
2324
+ const [identifier, setIdentifier] = (0, import_react2.useState)("");
2325
+ const [password, setPassword] = (0, import_react2.useState)("");
2326
+ const [username, setUsername] = (0, import_react2.useState)("");
2327
+ const [phone, setPhone] = (0, import_react2.useState)("");
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
+ };
2338
+ const handleLogin = async (e) => {
2339
+ e.preventDefault();
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
+ }
2351
+ };
2352
+ const handleRegister = async (e) => {
2353
+ e.preventDefault();
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
+ }
2365
+ };
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(
2373
+ "input",
2374
+ {
2375
+ style: inputStyle,
2376
+ type: "text",
2377
+ placeholder: "Email, phone, or username",
2378
+ value: identifier,
2379
+ onChange: (e) => setIdentifier(e.target.value),
2380
+ required: true
2381
+ }
2382
+ ), /* @__PURE__ */ import_react2.default.createElement(
2383
+ "input",
2384
+ {
2385
+ style: inputStyle,
2386
+ type: "password",
2387
+ placeholder: "Password",
2388
+ value: password,
2389
+ onChange: (e) => setPassword(e.target.value),
2390
+ required: true
2391
+ }
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(
2393
+ "input",
2394
+ {
2395
+ style: inputStyle,
2396
+ type: "text",
2397
+ placeholder: "Email",
2398
+ value: identifier,
2399
+ onChange: (e) => setIdentifier(e.target.value),
2400
+ required: true
2401
+ }
2402
+ ), /* @__PURE__ */ import_react2.default.createElement(
2403
+ "input",
2404
+ {
2405
+ style: inputStyle,
2406
+ type: "password",
2407
+ placeholder: "Password",
2408
+ value: password,
2409
+ onChange: (e) => setPassword(e.target.value),
2410
+ required: true
2411
+ }
2412
+ ), /* @__PURE__ */ import_react2.default.createElement(
2413
+ "input",
2414
+ {
2415
+ style: inputStyle,
2416
+ type: "text",
2417
+ placeholder: "Username (optional)",
2418
+ value: username,
2419
+ onChange: (e) => setUsername(e.target.value)
2420
+ }
2421
+ ), /* @__PURE__ */ import_react2.default.createElement(
2422
+ "input",
2423
+ {
2424
+ style: inputStyle,
2425
+ type: "text",
2426
+ placeholder: "Phone (optional)",
2427
+ value: phone,
2428
+ onChange: (e) => setPhone(e.target.value)
2429
+ }
2430
+ ), /* @__PURE__ */ import_react2.default.createElement("button", { style: buttonStyle, type: "submit" }, "Register")), message && /* @__PURE__ */ import_react2.default.createElement("div", { style: messageStyle(success) }, message));
2431
+ }
2432
+
2433
+ // src/components/LoginOnly.jsx
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
+ });
2473
+ function LoginOnly() {
2474
+ const [identifier, setIdentifier] = (0, import_react3.useState)("");
2475
+ const [password, setPassword] = (0, import_react3.useState)("");
2476
+ const [message, setMessage] = (0, import_react3.useState)(null);
2477
+ const [success, setSuccess] = (0, import_react3.useState)(false);
2478
+ const handleLogin = async (e) => {
2479
+ e.preventDefault();
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
+ }
2496
+ };
2497
+ return /* @__PURE__ */ import_react3.default.createElement("div", { style: boxStyle2 }, /* @__PURE__ */ import_react3.default.createElement("form", { onSubmit: handleLogin }, /* @__PURE__ */ import_react3.default.createElement(
2498
+ "input",
2499
+ {
2500
+ style: inputStyle2,
2501
+ type: "text",
2502
+ placeholder: "Email, phone, or username",
2503
+ value: identifier,
2504
+ onChange: (e) => setIdentifier(e.target.value),
2505
+ required: true
2506
+ }
2507
+ ), /* @__PURE__ */ import_react3.default.createElement(
2508
+ "input",
2509
+ {
2510
+ style: inputStyle2,
2511
+ type: "password",
2512
+ placeholder: "Password",
2513
+ value: password,
2514
+ onChange: (e) => setPassword(e.target.value),
2515
+ required: true
2516
+ }
2517
+ ), /* @__PURE__ */ import_react3.default.createElement("button", { style: buttonStyle2, type: "submit" }, "Login")), message && /* @__PURE__ */ import_react3.default.createElement("div", { style: messageStyle2(success) }, message));
2518
+ }
2519
+
2520
+ // src/components/RegisterOnly.jsx
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
+ });
2560
+ function RegisterOnly() {
2561
+ const [email, setEmail] = (0, import_react4.useState)("");
2562
+ const [password, setPassword] = (0, import_react4.useState)("");
2563
+ const [username, setUsername] = (0, import_react4.useState)("");
2564
+ const [phone, setPhone] = (0, import_react4.useState)("");
2565
+ const [message, setMessage] = (0, import_react4.useState)(null);
2566
+ const [success, setSuccess] = (0, import_react4.useState)(false);
2567
+ const handleRegister = async (e) => {
2568
+ e.preventDefault();
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
+ }
2587
+ };
2588
+ return /* @__PURE__ */ import_react4.default.createElement("div", { style: boxStyle3 }, /* @__PURE__ */ import_react4.default.createElement("form", { onSubmit: handleRegister }, /* @__PURE__ */ import_react4.default.createElement(
2589
+ "input",
2590
+ {
2591
+ style: inputStyle3,
2592
+ type: "text",
2593
+ placeholder: "Email",
2594
+ value: email,
2595
+ onChange: (e) => setEmail(e.target.value),
2596
+ required: true
2597
+ }
2598
+ ), /* @__PURE__ */ import_react4.default.createElement(
2599
+ "input",
2600
+ {
2601
+ style: inputStyle3,
2602
+ type: "password",
2603
+ placeholder: "Password",
2604
+ value: password,
2605
+ onChange: (e) => setPassword(e.target.value),
2606
+ required: true
2607
+ }
2608
+ ), /* @__PURE__ */ import_react4.default.createElement(
2609
+ "input",
2610
+ {
2611
+ style: inputStyle3,
2612
+ type: "text",
2613
+ placeholder: "Username (optional)",
2614
+ value: username,
2615
+ onChange: (e) => setUsername(e.target.value)
2616
+ }
2617
+ ), /* @__PURE__ */ import_react4.default.createElement(
2618
+ "input",
2619
+ {
2620
+ style: inputStyle3,
2621
+ type: "text",
2622
+ placeholder: "Phone (optional)",
2623
+ value: phone,
2624
+ onChange: (e) => setPhone(e.target.value)
2625
+ }
2626
+ ), /* @__PURE__ */ import_react4.default.createElement("button", { style: buttonStyle3, type: "submit" }, "Register")), message && /* @__PURE__ */ import_react4.default.createElement("div", { style: messageStyle3(success) }, message));
2627
+ }
2628
+
2629
+ // src/components/LogoutButton.jsx
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
+ });
2660
+ function LogoutButton() {
2661
+ const [message, setMessage] = (0, import_react5.useState)(null);
2662
+ const [success, setSuccess] = (0, import_react5.useState)(false);
2663
+ const handleLogout = async () => {
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
+ }
2678
+ };
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));
2680
+ }
2316
2681
  export {
2317
- AuthWrapper,
2682
+ LoginOnly,
2683
+ LoginRegisterFlow,
2318
2684
  LogoutButton,
2685
+ RegisterOnly,
2319
2686
  initializeSupabase,
2320
2687
  isAdmin,
2321
2688
  logout,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xouteiro/auth_npm",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Authentication package for Supabase",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -0,0 +1,96 @@
1
+ import React, { useState } from 'react';
2
+ import { signInWithEmail } from '../login';
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
+
46
+ export default function LoginOnly() {
47
+ const [identifier, setIdentifier] = useState('');
48
+ const [password, setPassword] = useState('');
49
+ const [message, setMessage] = useState(null);
50
+ const [success, setSuccess] = useState(false);
51
+
52
+ const handleLogin = async (e) => {
53
+ e.preventDefault();
54
+ setMessage(null);
55
+ setSuccess(false);
56
+ const { error } = await signInWithEmail(identifier, password);
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
+ }
70
+ };
71
+
72
+ return (
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>
95
+ );
96
+ }