-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from Princekumarofficial/main
Google Authentication
- Loading branch information
Showing
8 changed files
with
195 additions
and
66 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from "react"; | ||
import GoogleButton from "react-google-button"; | ||
import { googleLoginURL } from "@/helpers/googleAuth"; | ||
import googleLogo from "@/../public/google_icon.svg"; | ||
|
||
const GoogleLoginButton = ({ onClick }) => { | ||
return ( | ||
<button | ||
className="bg-white h-2rem pl-2 pr-4 flex items-center border-2 border-gray-200 rounded-xl hover:shadow-inner transition-shadow" | ||
onClick={onClick} | ||
> | ||
<img | ||
src={googleLogo.src} | ||
alt="" | ||
className="aspect-square h-12 float-left" | ||
/> | ||
Login With google | ||
</button> | ||
); | ||
}; | ||
|
||
const GoogleLogin = () => { | ||
const loginURL = googleLoginURL(); | ||
return ( | ||
<div> | ||
<GoogleLoginButton | ||
onClick={() => { | ||
window.location.href = loginURL; | ||
}} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GoogleLogin; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -7,6 +7,9 @@ import toast, { Toaster } from "react-hot-toast"; | |
import { useRouter } from "next/navigation"; | ||
import Cookies from "js-cookie"; | ||
import { jwtDecode } from "jwt-decode"; | ||
import GoogleLogin from "./googleLogin"; | ||
import { LoginWithEmail } from "@/components/loginForms/loginWithEmail"; | ||
|
||
const LoginForm = () => { | ||
const [email, setemail] = useState<String | null>(null); | ||
const [role, setrole] = useState<String | null>("STUDENT"); | ||
|
@@ -18,42 +21,44 @@ const LoginForm = () => { | |
<div className="bg-white p-4 px-4 md:p-8 rounded-md"> | ||
<div className="w-full"> | ||
<div className="lg:col-span-2 w-full"> | ||
<div className="my-2 w-full"> | ||
<div className="md:col-span-5"> | ||
<input | ||
type="text" | ||
name="email" | ||
id="email" | ||
className="h-10 border mt-1 rounded px-4 w-full bg-gray-50" | ||
placeholder="[email protected]" | ||
required={true} | ||
onChange={(e) => { | ||
setemail(e?.target?.value); | ||
}} | ||
/> | ||
</div> | ||
<div className="md:col-span-5"> | ||
<select | ||
name="role" | ||
id="role" | ||
className="h-10 border mt-1 rounded px-4 w-full bg-gray-50" | ||
required={true} | ||
onChange={(e) => { | ||
setrole(e?.target?.value); | ||
}} | ||
> | ||
<option>Student</option> | ||
<option>Faculty</option> | ||
<option>Recruiter</option> | ||
<option>Manager</option> | ||
<option>Admin</option> | ||
</select> | ||
<div className="my-2 w-full h-max"> | ||
<div className="mb-4"> | ||
<div className="md:col-span-5"> | ||
<input | ||
type="text" | ||
name="email" | ||
id="email" | ||
className="h-10 border mt-1 rounded px-4 w-full bg-gray-50" | ||
placeholder="[email protected]" | ||
required={true} | ||
onChange={(e) => { | ||
setemail(e?.target?.value); | ||
}} | ||
/> | ||
</div> | ||
<div className="md:col-span-5"> | ||
<select | ||
name="role" | ||
id="role" | ||
className="h-10 border mt-1 rounded px-4 w-full bg-gray-50" | ||
required={true} | ||
onChange={(e) => { | ||
setrole(e?.target?.value); | ||
}} | ||
> | ||
<option>Student</option> | ||
<option>Faculty</option> | ||
<option>Recruiter</option> | ||
<option>Manager</option> | ||
<option>Admin</option> | ||
</select> | ||
</div> | ||
</div> | ||
|
||
<div className="md:col-span-5 text-right"> | ||
<div className=" items-center flex justify-center"> | ||
<div className="items-center flex justify-center flex-col gap-4"> | ||
<button | ||
className="bg-blue-500 my-5 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" | ||
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" | ||
onClick={() => { | ||
if (email == null || email.length == 0) { | ||
toast.error("Email is Required"); | ||
|
@@ -71,18 +76,18 @@ const LoginForm = () => { | |
response.data.accessToken, | ||
{ | ||
expires: 365, | ||
}, | ||
} | ||
); | ||
Cookies.set( | ||
"user", | ||
JSON.stringify( | ||
jwtDecode(response.data.accessToken), | ||
jwtDecode(response.data.accessToken) | ||
), | ||
{ expires: 365 }, | ||
{ expires: 365 } | ||
); | ||
toast.success("logged in"); | ||
window.location.href = "/"; | ||
}, | ||
} | ||
) | ||
.catch((err) => { | ||
alert(err); | ||
|
@@ -92,6 +97,8 @@ const LoginForm = () => { | |
> | ||
Request Access | ||
</button> | ||
<LoginWithEmail email={email} /> | ||
<GoogleLogin /> | ||
</div> | ||
</div> | ||
</div> | ||
|
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from "react"; | ||
import { url } from "../../helpers/api"; | ||
import LockImg from "@/../public/icons/lock.svg"; | ||
import toast from "react-hot-toast"; | ||
|
||
export const LoginWithEmail = (params: { email: String }) => { | ||
const onClick = async () => { | ||
const res = await fetch(url("/auth/passwordless"), { | ||
method: "POST", | ||
cache: "no-store", | ||
headers: { | ||
"Content-type": "application/json", | ||
}, | ||
body: JSON.stringify({ email: params.email }), | ||
}); | ||
console.log(res); | ||
const resOk = res.ok; | ||
if (resOk) toast.success("Email Has Been Sent"); | ||
return resOk; | ||
}; | ||
|
||
return ( | ||
<> | ||
<div> | ||
<button | ||
className="bg-white h-2rem px-4 py-2 flex items-center border-2 border-gray-200 rounded-xl hover:shadow-inner transition-shadow" | ||
onClick={onClick} | ||
> | ||
<span> | ||
<img src={LockImg.src} className="h-8 mr-1" alt="" /> | ||
</span> | ||
Login With Email | ||
</button> | ||
</div> | ||
</> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const baseUrl = process.env.NEXT_PUBLIC_BACKEND_URL; | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; | ||
|
||
export const url = (NextUrl: string) => { | ||
return `${baseUrl}/api/v1${NextUrl}`; | ||
}; | ||
|
||
export const googleLoginURL = () => { | ||
const googleLoginURL = url("/auth/google/login"); | ||
return googleLoginURL; | ||
}; |
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