@@ -3,26 +3,31 @@ import { useRouter } from "next/router";
33import PageSeo from "@components/seo/page-seo" ;
44import Layout from "@layout/layout-01" ;
55import Breadcrumb from "@components/breadcrumb" ;
6- import LoginForm from "@components/forms/login-form" ;
76import Spinner from "@ui/spinner" ;
8- import { useUser } from "@contexts/user-context" ;
97import { useMount } from "@hooks" ;
108import WelcomeMessage from "@components/welcome-message" ;
9+ import { useSession , signIn , signOut } from "next-auth/react" ;
1110
1211const Login = ( ) => {
1312 const mounted = useMount ( ) ;
14- const { isLoggedIn , logout } = useUser ( ) ;
13+ const { data : session , status } = useSession ( ) ;
1514 const router = useRouter ( ) ;
1615
1716 useEffect ( ( ) => {
18- if ( isLoggedIn ) {
19- void router . push ( "/profile" ) ; // Redirect to dashboard if already logged in
17+ if ( status === "authenticated" ) {
18+ void router . push ( "/profile" ) ; // Redirect to profile if logged in
2019 }
21- } , [ isLoggedIn , router ] ) ;
20+ } , [ status , router ] ) ;
2221
23- if ( ! mounted ) return null ;
22+ if ( ! mounted || status === "loading" ) {
23+ return (
24+ < div className = "tw-fixed tw-bg-light-100 tw-top-0 tw-z-50 tw-w-screen tw-h-screen tw-flex tw-justify-center tw-items-center" >
25+ < Spinner />
26+ </ div >
27+ ) ;
28+ }
2429
25- if ( ! isLoggedIn ) {
30+ if ( ! session ) {
2631 return (
2732 < >
2833 < PageSeo title = "Login" description = "Login to your account" />
@@ -36,7 +41,12 @@ const Login = () => {
3641 < WelcomeMessage />
3742 </ div >
3843 < div className = "tw-flex tw-items-center tw-w-full lg:tw-w-3/4 tw-mx-auto" >
39- < LoginForm />
44+ < button
45+ onClick = { ( ) => signIn ( "github" ) }
46+ className = "tw-bg-primary tw-text-white tw-py-2 tw-px-4 tw-rounded"
47+ >
48+ Sign in with GitHub
49+ </ button >
4050 </ div >
4151 </ div >
4252 </ >
@@ -46,7 +56,11 @@ const Login = () => {
4656 return (
4757 < div className = "tw-fixed tw-bg-light-100 tw-top-0 tw-z-50 tw-w-screen tw-h-screen tw-flex tw-justify-center tw-items-center" >
4858 < Spinner />
49- < button type = "button" onClick = { logout } >
59+ < button
60+ type = "button"
61+ onClick = { ( ) => signOut ( ) }
62+ className = "tw-bg-red-500 tw-text-white tw-py-2 tw-px-4 tw-rounded"
63+ >
5064 Logout
5165 </ button >
5266 </ div >
@@ -67,4 +81,4 @@ export const getStaticProps = () => {
6781 } ;
6882} ;
6983
70- export default Login ;
84+ export default Login ;
0 commit comments