Skip to content

Commit 8a7d139

Browse files
committed
testing redirection
1 parent 5a08118 commit 8a7d139

File tree

1 file changed

+79
-76
lines changed

1 file changed

+79
-76
lines changed

src/views/login/login.tsx

Lines changed: 79 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,62 @@
1-
import React, {useEffect, useState} from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import Image from 'next/image';
33
import logo from '../../../public/images/logo.png';
44
import Link from 'next/link';
55
import MiniFooter from '@/components/global/minifooter';
6-
import {signIn, useSession} from "next-auth/react";
7-
import {useRouter} from "next/router";
8-
import Spinner from "@/components/common/Spinner";
9-
import {mockProviders} from "next-auth/client/__tests__/helpers/mocks";
6+
import { signIn, useSession } from 'next-auth/react';
7+
import { useRouter } from 'next/router';
8+
import Spinner from '@/components/common/Spinner';
9+
import { mockProviders } from 'next-auth/client/__tests__/helpers/mocks';
1010
import callbackUrl = mockProviders.github.callbackUrl;
1111
import { TextField } from '@mui/material';
1212

1313
const LoginComponent = () => {
14-
const {data: session, status, update} = useSession()
14+
const { data: session, status, update } = useSession();
1515
const [email, setEmail] = useState('');
1616
const [password, setPassword] = useState('');
1717
const [successMessage, setSuccessMessage] = useState('');
1818
const router = useRouter();
1919
const [errorMessage, setErrorMessage] = useState('');
2020
const [loading, setLoading] = useState(false);
21-
const {query} = router;
21+
const { query } = router;
2222
const handleLoginWithGoogle = async () => {
23-
2423
try {
25-
setLoading(true)
24+
setLoading(true);
2625

27-
const googleSignInResponse = await signIn("cognito_google", {
26+
const googleSignInResponse = await signIn('cognito_google', {
2827
redirect: false,
29-
callbackUrl: `http://localhost:3000${query?.callBack}`
30-
})
31-
console.log("googleSignInResponse:", googleSignInResponse)
28+
callbackUrl: `http://localhost:3000${query?.callBack}`,
29+
});
30+
console.log('googleSignInResponse:', googleSignInResponse);
3231
if (googleSignInResponse?.error) {
33-
setErrorMessage(googleSignInResponse.error)
34-
setLoading(false)
32+
setErrorMessage(googleSignInResponse.error);
33+
setLoading(false);
3534
}
3635
} catch (error: any) {
3736
console.error('Error initiating Google login:', error);
38-
setLoading(false)
39-
setErrorMessage(error.message)
37+
setLoading(false);
38+
setErrorMessage(error.message);
4039
}
4140
};
4241

4342
async function handleLogin() {
44-
setLoading(true)
43+
setLoading(true);
4544
try {
46-
const signInResponse = await signIn("Credentials_signIn", {
45+
const signInResponse = await signIn('Credentials_signIn', {
4746
email,
4847
password,
49-
redirect: false,
50-
callbackUrl: `http://localhost:3000${query?.callBack}`
51-
})
52-
console.log("signInResponse:", signInResponse)
48+
redirect: true,
49+
callbackUrl: `http://localhost:3000${query?.callBack}`,
50+
});
51+
console.log('signInResponse:', signInResponse);
5352
if (signInResponse?.error) {
54-
setErrorMessage(signInResponse.error)
55-
setLoading(false)
56-
}
53+
setErrorMessage(signInResponse.error);
54+
setLoading(false);
55+
}
5756
} catch (error: any) {
5857
console.error('Error initiating cognito login:', error);
59-
setErrorMessage(error.message)
60-
setLoading(false)
58+
setErrorMessage(error.message);
59+
setLoading(false);
6160
}
6261
}
6362

@@ -66,70 +65,74 @@ const LoginComponent = () => {
6665
// }, []
6766
// )
6867
return (
69-
<div className="main-box bg-dark-600" style={{height: 'auto !important', minHeight: '100vh'}}>
70-
<div style={{display: 'flex', flexDirection: 'column', alignItems: 'center'}}>
71-
<Image src={logo} alt="logo" className="mt-10 text-center"/>
72-
<div className="px-10 py-5 bg-white rounded whitebox mt-11" style={{height: '546px', width: '464px'}}>
73-
<p className="mt-4 text-xl text-center text-black font-weight-bold" style={{fontSize: '1.4rem'}}>
68+
<div className="main-box bg-dark-600" style={{ height: 'auto !important', minHeight: '100vh' }}>
69+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
70+
<Image src={logo} alt="logo" className="mt-10 text-center" />
71+
<div className="px-10 py-5 bg-white rounded whitebox mt-11" style={{ height: '546px', width: '464px' }}>
72+
<p className="mt-4 text-xl text-center text-black font-weight-bold" style={{ fontSize: '1.4rem' }}>
7473
Login
7574
</p>
76-
{errorMessage && <div
77-
className="relative block w-full p-4 mt-5 text-base leading-5 text-white bg-red-500 rounded-lg opacity-100 font-regular">
78-
{errorMessage}
79-
</div>}
80-
{successMessage && <div
81-
className="relative block w-full p-4 mt-5 text-base leading-5 text-white bg-green-500 rounded-lg opacity-100 font-regular">
82-
{successMessage}
83-
</div>}
84-
{loading && <div className={'align-items-center d-flex flex justify-center mt-3'}>
85-
<Spinner height={'1rem'} width={'1rem'}/>
86-
</div>}
87-
<button
75+
{errorMessage && (
76+
<div className="relative block w-full p-4 mt-5 text-base leading-5 text-white bg-red-500 rounded-lg opacity-100 font-regular">
77+
{errorMessage}
78+
</div>
79+
)}
80+
{successMessage && (
81+
<div className="relative block w-full p-4 mt-5 text-base leading-5 text-white bg-green-500 rounded-lg opacity-100 font-regular">
82+
{successMessage}
83+
</div>
84+
)}
85+
{loading && (
86+
<div className={'align-items-center d-flex flex justify-center mt-3'}>
87+
<Spinner height={'1rem'} width={'1rem'} />
88+
</div>
89+
)}
90+
<button
8891
type="button"
8992
onClick={() => handleLoginWithGoogle()}
9093
className="w-full mt-5 text-center hidden justify-center focus:ring-0 focus:outline-none rounded border border-dark-200 md:text-md sm:text-sm text-[10px] px-5 py-3 inline-flex items-center mb-2"
9194
>
92-
<img src="/images/google.svg" alt=""/>
93-
<span
94-
className="uppercase font-medium text-dark-600 ml-1 sm:ml-2 tracking-[1.5px]">continue with google</span>
95+
<img src="/images/google.svg" alt="" />
96+
<span className="uppercase font-medium text-dark-600 ml-1 sm:ml-2 tracking-[1.5px]">continue with google</span>
9597
</button>
9698

9799
{/* <p className="mt-5 text-center text-black text-md font-weight-bold">or</p> */}
98-
<br/>
99-
<br/>
100-
<br/>
100+
<br />
101+
<br />
102+
<br />
103+
<TextField
104+
label="Email"
105+
id="email"
106+
size="small"
107+
variant="standard"
108+
type="text"
109+
className="w-full mb-6"
110+
onChange={(e) => setEmail(e.target.value)}
111+
required
112+
/>
101113
<TextField
102-
label="Email"
103-
id="email"
104-
size="small"
105-
variant="standard"
106-
type="text"
107-
className="w-full mb-6"
108-
onChange={(e) => setEmail(e.target.value)}
109-
required
110-
/>
111-
<TextField
112-
label="Password"
113-
id="password"
114-
size="small"
115-
variant="standard"
116-
type="password"
117-
className="w-full mb-6"
118-
onChange={(e) => setPassword(e.target.value)}
119-
required
120-
/>
114+
label="Password"
115+
id="password"
116+
size="small"
117+
variant="standard"
118+
type="password"
119+
className="w-full mb-6"
120+
onChange={(e) => setPassword(e.target.value)}
121+
required
122+
/>
121123

122124
<button
123125
onClick={() => handleLogin()}
124-
className="w-full py-2 mt-8 text-center text-white rounded font-weight-bold bg-dark-600">LOGIN
126+
className="w-full py-2 mt-8 text-center text-white rounded font-weight-bold bg-dark-600"
127+
>
128+
LOGIN
125129
</button>
126-
<p className="text-xl text-center text-black font-weight-bold mt-9"
127-
style={{color: '#1976D2', fontSize: '14px'}}>
130+
<p className="text-xl text-center text-black font-weight-bold mt-9" style={{ color: '#1976D2', fontSize: '14px' }}>
128131
Reset Password
129132
</p>
130133
<Link href="/register">
131-
<p className="mt-5 text-xl text-center text-black font-weight-bold" style={{fontSize: '14px'}}>
132-
No account? <span style={{color: '#1976D2'}}>Create one</span>
134+
<p className="mt-5 text-xl text-center text-black font-weight-bold" style={{ fontSize: '14px' }}>
135+
No account? <span style={{ color: '#1976D2' }}>Create one</span>
133136
</p>
134137
</Link>
135138
<style>
@@ -180,7 +183,7 @@ const LoginComponent = () => {
180183
</style>
181184
</div>
182185
</div>
183-
<MiniFooter/>
186+
<MiniFooter />
184187
</div>
185188
);
186189
};

0 commit comments

Comments
 (0)