From 99cd673b1219a3b0164ee2039f2aaa3755866c02 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Sun, 19 Nov 2023 16:49:03 +0800 Subject: [PATCH] Made remember me in login fully functional --- src/Components/API/API.tsx | 6 ++++-- src/Components/LoginModal/LoginModal.tsx | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Components/API/API.tsx b/src/Components/API/API.tsx index 93e20cc..4a6a7e2 100644 --- a/src/Components/API/API.tsx +++ b/src/Components/API/API.tsx @@ -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; diff --git a/src/Components/LoginModal/LoginModal.tsx b/src/Components/LoginModal/LoginModal.tsx index e5f9d34..e570756 100644 --- a/src/Components/LoginModal/LoginModal.tsx +++ b/src/Components/LoginModal/LoginModal.tsx @@ -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)} />

Remember me

@@ -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");