Made remember me in login fully functional

This commit is contained in:
Keannu Bernasol 2023-11-19 16:49:03 +08:00
parent 44ecc4ec7c
commit 99cd673b12
2 changed files with 9 additions and 6 deletions

View file

@ -51,13 +51,15 @@ export function RegisterAPI(register: RegisterType) {
}); });
} }
export function LoginAPI(user: LoginType) { export function LoginAPI(user: LoginType, remember_session: boolean) {
return instance return instance
.post("api/v1/accounts/jwt/create/", user) .post("api/v1/accounts/jwt/create/", user)
.then(async (response) => { .then(async (response) => {
console.log(response.data); console.log(response.data);
setAccessToken(response.data.access); setAccessToken(response.data.access);
setRefreshToken(response.data.refresh); if (remember_session) {
setRefreshToken(response.data.refresh);
}
console.log("Login Success "); console.log("Login Success ");
return true; return true;

View file

@ -16,7 +16,7 @@ import { auth_toggle } from "../Plugins/Redux/Slices/AuthSlice/AuthSlice";
export default function LoginModal() { export default function LoginModal() {
const navigate = useNavigate(); const navigate = useNavigate();
const [showPassword, setShowPassword] = useState(false); const [showPassword, setShowPassword] = useState(false);
const [remember, setRemember] = useState(true); const [remember_session, setRememberSession] = useState(true);
const [error, setError] = useState(""); const [error, setError] = useState("");
const [user, setUser] = useState({ const [user, setUser] = useState({
username: "", username: "",
@ -96,8 +96,8 @@ export default function LoginModal() {
color: colors.button_dark, color: colors.button_dark,
}, },
}} }}
value={remember} value={remember_session}
onChange={() => setRemember(!remember)} onChange={() => setRememberSession(!remember_session)}
/> />
<p style={{ ...styles.text_dark, ...styles.text_S }}>Remember me</p> <p style={{ ...styles.text_dark, ...styles.text_S }}>Remember me</p>
</div> </div>
@ -126,9 +126,10 @@ export default function LoginModal() {
type={"dark"} type={"dark"}
label={"Login"} label={"Login"}
onClick={async () => { onClick={async () => {
const status = await LoginAPI(user); const status = await LoginAPI(user, remember_session);
if (status === true) { if (status === true) {
await dispatch(auth_toggle()); await dispatch(auth_toggle());
navigate("/dashboard"); navigate("/dashboard");
} else { } else {
setError("Invalid login"); setError("Invalid login");