-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: access token and refresh token login in dashboard
- Loading branch information
1 parent
f9dbd72
commit d1f08b1
Showing
8 changed files
with
51 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,67 @@ | ||
"use client"; | ||
import { Button, Image } from "@/components/common"; | ||
import { useRouter } from "next/navigation"; | ||
'use client'; | ||
import { useFormik } from 'formik'; | ||
import { useRouter } from 'next/navigation'; | ||
import { Button, Image } from '@/components/common'; | ||
import { loginSchema } from '@/schemas/login'; | ||
import { useUserLoginMutation } from '@/redux/api/authApi'; | ||
import { getNewAccessToken } from '@/services/auth.service'; | ||
|
||
function Login() { | ||
const router = useRouter(); | ||
|
||
const [login, { data }] = useUserLoginMutation(); | ||
// console.log(data); | ||
|
||
const formik = useFormik({ | ||
initialValues: { | ||
email: '', | ||
password: '', | ||
}, | ||
validationSchema: loginSchema, | ||
onSubmit: async values => { | ||
await login(values); | ||
alert(JSON.stringify(values, null, 2)); | ||
}, | ||
}); | ||
|
||
const handleRefresh = async () => { | ||
const token = await getNewAccessToken(); | ||
console.log(token); | ||
}; | ||
|
||
return ( | ||
<div className="flex h-screen flex-wrap items-center justify-center overflow-x-hidden bg-bgwhite md:gap-[60px]"> | ||
<Image | ||
className="h-[300px] w-[100%] rounded-rounded-md md:h-[500px] md:w-[500px]" | ||
src="/static/pictures/login.png" | ||
alt="Login image of RSE dashboard" | ||
/> | ||
<div className="mx-2 flex w-full flex-col items-end justify-center gap-3 md:mx-0 md:h-[500px] md:w-[500px]"> | ||
|
||
<form | ||
onSubmit={formik.handleSubmit} | ||
className="mx-2 flex w-full flex-col items-end justify-center gap-3 md:mx-0 md:h-[500px] md:w-[500px]" | ||
> | ||
<input | ||
type="text" | ||
type="email" | ||
placeholder="Type your email here..." | ||
className="h-[50px] w-full rounded-rounded-md bg-white-c p-[22px] text-black-c placeholder-gray-600 shadow-default focus:outline-none" | ||
{...formik.getFieldProps('email')} | ||
/> | ||
<input | ||
type="password" | ||
placeholder="Type your password here..." | ||
className="h-[50px] w-full rounded-rounded-md bg-white-c p-[22px] text-black-c placeholder-gray-600 shadow-default focus:outline-none" | ||
{...formik.getFieldProps('password')} | ||
/> | ||
<Button className="h-[50px]" onClick={() => router.push("/dashboard")}> | ||
<Button type="submit" className="h-[50px]"> | ||
LOG IN | ||
</Button> | ||
</div> | ||
<Button className="h-[50px]" onClick={handleRefresh}> | ||
check refresh | ||
</Button> | ||
</form> | ||
</div> | ||
); | ||
} | ||
export default Login; | ||
// onClick={() => router.push('/dashboard')} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const getBaseUrl = (): string => { | ||
return process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3030/api/v1'; | ||
return process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:5000/api/v1'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as yup from "yup"; | ||
import * as yup from 'yup'; | ||
|
||
export const loginSchema = yup.object().shape({ | ||
id: yup.string().required("UserId is required"), | ||
email: yup.string().email().required('Email is required'), | ||
password: yup.string().min(6).max(32).required(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters