File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import Link from "next/link" ;
2+ import { useRouter } from "next/router" ;
23import { useState } from "react" ;
34
45import { Button } from "@/components/ui/button" ;
@@ -12,22 +13,25 @@ import {
1213} from "@/components/ui/card" ;
1314import { Input } from "@/components/ui/input" ;
1415import api from "@/lib/api" ;
15- import { setTokens } from "@/lib/auth" ;
16+ import { clearTokens , setTokens } from "@/lib/auth" ;
1617
1718export 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 (
You can’t perform that action at this time.
0 commit comments