mirror of
https://github.com/lemeow125/EquipmentTracker-Frontend.git
synced 2024-11-17 06:09:25 +08:00
Made remember me in login fully functional
This commit is contained in:
parent
44ecc4ec7c
commit
99cd673b12
2 changed files with 9 additions and 6 deletions
|
@ -51,13 +51,15 @@ export function RegisterAPI(register: RegisterType) {
|
|||
});
|
||||
}
|
||||
|
||||
export function LoginAPI(user: LoginType) {
|
||||
export function LoginAPI(user: LoginType, remember_session: boolean) {
|
||||
return instance
|
||||
.post("api/v1/accounts/jwt/create/", user)
|
||||
.then(async (response) => {
|
||||
console.log(response.data);
|
||||
setAccessToken(response.data.access);
|
||||
setRefreshToken(response.data.refresh);
|
||||
if (remember_session) {
|
||||
setRefreshToken(response.data.refresh);
|
||||
}
|
||||
|
||||
console.log("Login Success ");
|
||||
return true;
|
||||
|
|
|
@ -16,7 +16,7 @@ import { auth_toggle } from "../Plugins/Redux/Slices/AuthSlice/AuthSlice";
|
|||
export default function LoginModal() {
|
||||
const navigate = useNavigate();
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [remember, setRemember] = useState(true);
|
||||
const [remember_session, setRememberSession] = useState(true);
|
||||
const [error, setError] = useState("");
|
||||
const [user, setUser] = useState({
|
||||
username: "",
|
||||
|
@ -96,8 +96,8 @@ export default function LoginModal() {
|
|||
color: colors.button_dark,
|
||||
},
|
||||
}}
|
||||
value={remember}
|
||||
onChange={() => setRemember(!remember)}
|
||||
value={remember_session}
|
||||
onChange={() => setRememberSession(!remember_session)}
|
||||
/>
|
||||
<p style={{ ...styles.text_dark, ...styles.text_S }}>Remember me</p>
|
||||
</div>
|
||||
|
@ -126,9 +126,10 @@ export default function LoginModal() {
|
|||
type={"dark"}
|
||||
label={"Login"}
|
||||
onClick={async () => {
|
||||
const status = await LoginAPI(user);
|
||||
const status = await LoginAPI(user, remember_session);
|
||||
if (status === true) {
|
||||
await dispatch(auth_toggle());
|
||||
|
||||
navigate("/dashboard");
|
||||
} else {
|
||||
setError("Invalid login");
|
||||
|
|
Loading…
Reference in a new issue