1+ import { useState } from "react" ;
2+
13import { Button } from "@/components/ui/button" ;
24import {
35 Card ,
@@ -8,8 +10,25 @@ import {
810 CardTitle ,
911} from "@/components/ui/card" ;
1012import { Input } from "@/components/ui/input" ;
13+ import api from "@/lib/api" ;
14+ import { setTokens } from "@/lib/auth" ;
1115
1216export default function Login ( ) {
17+ // form variables
18+ const [ username , setUsername ] = useState ( "" ) ;
19+ const [ password , setPassword ] = useState ( "" ) ;
20+
21+ //function to return JWT
22+ const login = async ( username : string , password : string ) => {
23+ const res = await api . post ( "/token/" , {
24+ username,
25+ password,
26+ } ) ;
27+
28+ const { access, refresh } = res . data ;
29+ setTokens ( access , refresh ) ;
30+ } ;
31+
1332 return (
1433 < div className = "flex min-h-screen items-center justify-center bg-muted" >
1534 < Card className = "w-full max-w-sm" >
@@ -25,10 +44,11 @@ export default function Login() {
2544 < div className = "flex flex-col gap-6" >
2645 < div className = "grid gap-2" >
2746 < Input
28- id = "email "
29- type = "email "
30- placeholder = "m@example.com "
47+ id = "username "
48+ type = "username "
49+ placeholder = "user-name "
3150 required
51+ onChange = { ( e ) => setUsername ( e . target . value ) }
3252 />
3353 </ div >
3454 < div className = "grid gap-2" >
@@ -40,18 +60,22 @@ export default function Login() {
4060 Forgot your password?
4161 </ a >
4262 </ div >
43- < Input id = "password" type = "password" required />
63+ < Input
64+ type = "password"
65+ onChange = { ( e ) => setPassword ( e . target . value ) }
66+ />
4467 </ div >
4568 </ div >
4669 </ form >
4770 </ CardContent >
4871 < CardFooter className = "flex-col gap-2" >
49- < Button type = "submit" className = "w-full" >
72+ < Button
73+ type = "submit"
74+ className = "w-full"
75+ onClick = { ( ) => login ( username , password ) }
76+ >
5077 Login
5178 </ Button >
52- < Button variant = "outline" className = "w-full" >
53- Login with Google
54- </ Button >
5579 </ CardFooter >
5680 </ Card >
5781 </ div >
0 commit comments