Skip to content

Commit 5b4ef36

Browse files
different user log in fixed by clearing local storage tokens
1 parent a88bef3 commit 5b4ef36

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

client/src/pages/login.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Link from "next/link";
2+
import { useRouter } from "next/router";
23
import { useState } from "react";
34

45
import { Button } from "@/components/ui/button";
@@ -12,22 +13,25 @@ import {
1213
} from "@/components/ui/card";
1314
import { Input } from "@/components/ui/input";
1415
import api from "@/lib/api";
15-
import { setTokens } from "@/lib/auth";
16+
import { clearTokens, setTokens } from "@/lib/auth";
1617

1718
export default function Login() {
18-
// form variables
19+
const router = useRouter();
1920
const [username, setUsername] = useState("");
2021
const [password, setPassword] = useState("");
2122

2223
//function to return JWT
2324
const login = async (username: string, password: string) => {
25+
clearTokens();
2426
const res = await api.post("/token/", {
2527
username,
2628
password,
2729
});
2830

2931
const { access, refresh } = res.data;
3032
setTokens(access, refresh);
33+
34+
router.push("/home");
3135
};
3236

3337
return (

0 commit comments

Comments
 (0)