Skip to content

Commit

Permalink
If user misses signup, then, he can re verify from signup page
Browse files Browse the repository at this point in the history
  • Loading branch information
Capta1nRaj committed Jan 28, 2024
1 parent e3de35e commit 1872347
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/app/signIn/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const SignInpage = () => {
const [password, setpassword] = useState('priyalcoc2')
const [otp, setotp] = useState('');

const [signInScene, setsignInScene] = useState(true);
const [signInScene, setsignInScene] = useState(false);
const [signUpVerifyScene, setsignUpVerifyScene] = useState(false);

const [errorMessage, seterrorMessage] = useState('');

Expand All @@ -22,16 +23,31 @@ const SignInpage = () => {
const statusCode = response.data.statusCode;

if (statusCode === 201) {
setsignInScene(false);
setsignInScene(true);
} else if (statusCode === 401) {
setsignUpVerifyScene(true);
}
seterrorMessage(message);
}

async function signInVerify() {
const data = { userName, otp }
const response = await axios.put('/api/signIn', data)

const message = response.data.message;
const statusCode = response.data.statusCode;

if (statusCode === 202) {
window.location.href = '/';
return;
} else {
seterrorMessage(message);
}
}

async function signInVerify() {
async function signUpVerify() {
const data = { userName, otp }
const response = await axios.put('/api/signIn', data)
const response = await axios.put('/api/signUp', data)

const message = response.data.message;
const statusCode = response.data.statusCode;
Expand All @@ -54,23 +70,28 @@ const SignInpage = () => {

return (
<>
{signInScene ?
{(!signInScene && !signUpVerifyScene) ?
<div className='flex flex-col gap-4 mt-4 ml-8'>
<p>Sign IN</p>
<p><input value={userName} onChange={(e) => setuserName(e.target.value)} className='text-black pl-2 py-2 placeholder:text-black' placeholder='user name' type="text" /></p>
<p><input value={password} onChange={(e) => setpassword(e.target.value)} className='text-black pl-2 py-2 placeholder:text-black' placeholder='password' type="password" /></p>
{errorMessage && <p className='text-red-600'>{errorMessage}</p>}
<button onClick={signIn} className="text-left cursor-pointer">submit</button>
<Link href={'/forgotPassword'} className="text-left cursor-pointer">forgot password</Link>
<Link href="/signUp">Sign UP</Link>
</div>
:
<div className='flex flex-col gap-4 mt-4 ml-8'>
<p>Sign IN Verify</p>
<p>Sign {signUpVerifyScene ? "UP" : "IN"} Verify</p>
<p><input value={userName} onChange={(e) => setuserName(e.target.value)} className='text-black pl-2 py-2 placeholder:text-black' placeholder='user name' type="text" readOnly={true} /></p>
<p><input value={otp} onChange={(e) => setotp(e.target.value)} className='text-black pl-2 py-2 placeholder:text-black' placeholder='otp' type="otp" /></p>
{errorMessage && <p className='text-red-600'>{errorMessage}</p>}
<button onClick={resendOTP} className="text-left cursor-pointer">resend OTP</button>
<button onClick={signInVerify} className="text-left cursor-pointer">submit</button>
{signUpVerifyScene ?
<button onClick={signUpVerify} className="text-left cursor-pointer">submit</button>
:
<button onClick={signInVerify} className="text-left cursor-pointer">submit</button>
}
</div>
}
</>
Expand Down
2 changes: 2 additions & 0 deletions src/app/signUp/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'

import axios from "axios"
import { useState } from "react"
import Link from 'next/link'

const SignUpPage = () => {
const [fullName, setfullName] = useState('Priyal Raj')
Expand Down Expand Up @@ -66,6 +67,7 @@ const SignUpPage = () => {
<p><input value={referredBy} onChange={(e) => setreferredBy(e.target.value)} className='text-black pl-2 py-2 placeholder:text-black' placeholder='referred by' type="password" /></p>
{errorMessage && <p className='text-red-600'>{errorMessage}</p>}
<button onClick={signUP} className="text-left cursor-pointer">submit</button>
<Link href="/signIn">Sign IN</Link>
</div>
:
<div className='flex flex-col gap-4 mt-4 ml-8'>
Expand Down

0 comments on commit 1872347

Please sign in to comment.