Login logout finally working
This commit is contained in:
+37
-34
@@ -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>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user