Login logout finally working

This commit is contained in:
hz
2025-05-13 00:12:13 -07:00
parent fbd48297e2
commit 8f1cba5f82
5 changed files with 135 additions and 55 deletions
+37 -34
View File
@@ -2,6 +2,7 @@ import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
import config from "../config";
import { useAuth } from "../AuthContext";
import PageWrapper from "../components/PageWrapper";
const styles = {
form: {
@@ -81,7 +82,7 @@ const Login = () => {
}
const data = await res.json();
login(data.token);
login(data.token);
navigate("/dashboard");
} catch (err) {
console.error("Login error:", err);
@@ -90,39 +91,41 @@ const Login = () => {
};
return (
<form onSubmit={handleSubmit} style={styles.form}>
<h2 style={styles.title}>Login</h2>
<input
type="text"
name="username"
placeholder="Username"
value={form.username}
onChange={handleChange}
style={styles.input}
required
/>
<input
type="password"
name="password"
placeholder="Password"
value={form.password}
onChange={handleChange}
style={styles.input}
required
/>
<div style={styles.buttonRow}>
<button type="submit" style={styles.button}>
Login
</button>
<button
type="button"
onClick={() => navigate("/register")}
style={styles.button}
>
Register
</button>
</div>
</form>
<PageWrapper center>
<form onSubmit={handleSubmit} style={styles.form}>
<h2 style={styles.title}>Login</h2>
<input
type="text"
name="username"
placeholder="Username"
value={form.username}
onChange={handleChange}
style={styles.input}
required
/>
<input
type="password"
name="password"
placeholder="Password"
value={form.password}
onChange={handleChange}
style={styles.input}
required
/>
<div style={styles.buttonRow}>
<button type="submit" style={styles.button}>
Login
</button>
<button
type="button"
onClick={() => navigate("/register")}
style={styles.button}
>
Register
</button>
</div>
</form>
</PageWrapper>
);
};