diff --git a/public/google_icon.svg b/public/google_icon.svg new file mode 100644 index 00000000..d949ddeb --- /dev/null +++ b/public/google_icon.svg @@ -0,0 +1,44 @@ + \ No newline at end of file diff --git a/public/icons/lock.svg b/public/icons/lock.svg new file mode 100644 index 00000000..a8318821 --- /dev/null +++ b/public/icons/lock.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/loginForms/googleLogin.tsx b/src/components/loginForms/googleLogin.tsx new file mode 100644 index 00000000..65bc86a2 --- /dev/null +++ b/src/components/loginForms/googleLogin.tsx @@ -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 ( + + ); +}; + +const GoogleLogin = () => { + const loginURL = googleLoginURL(); + return ( +
+ { + window.location.href = loginURL; + }} + /> +
+ ); +}; + +export default GoogleLogin; diff --git a/src/components/loginForms/googleLoginButton.tsx b/src/components/loginForms/googleLoginButton.tsx deleted file mode 100644 index be28c3fa..00000000 --- a/src/components/loginForms/googleLoginButton.tsx +++ /dev/null @@ -1,23 +0,0 @@ -"use client"; - -import React from "react"; -import { signIn } from "next-auth/react"; -import GoogleButton from "react-google-button"; -import { useSearchParams } from "next/navigation"; - -const GoogleLoginButton = () => { - const searchParams = useSearchParams(); - const callbackUrl = "/"; - - return ( -
- signIn("google", { callbackUrl: callbackUrl })} - > - Sign In With Google - -
- ); -}; - -export default GoogleLoginButton; diff --git a/src/components/loginForms/loginForm.tsx b/src/components/loginForms/loginForm.tsx index 876d9ebe..49f4fe31 100644 --- a/src/components/loginForms/loginForm.tsx +++ b/src/components/loginForms/loginForm.tsx @@ -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(null); const [role, setrole] = useState("STUDENT"); @@ -18,42 +21,44 @@ const LoginForm = () => {
-
-
- { - setemail(e?.target?.value); - }} - /> -
-
- +
+
+
+ { + setemail(e?.target?.value); + }} + /> +
+
+ +
-
+
+ +
diff --git a/src/components/loginForms/loginWithEmail.tsx b/src/components/loginForms/loginWithEmail.tsx new file mode 100644 index 00000000..55842182 --- /dev/null +++ b/src/components/loginForms/loginWithEmail.tsx @@ -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 ( + <> +
+ +
+ + ); +}; diff --git a/src/helpers/googleAuth.ts b/src/helpers/googleAuth.ts new file mode 100644 index 00000000..648b0bce --- /dev/null +++ b/src/helpers/googleAuth.ts @@ -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; +}; diff --git a/src/middleware.ts b/src/middleware.ts index 2bf3e388..b32cb0e8 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -2,20 +2,37 @@ import { NextResponse } from "next/server"; import type { NextRequest } from "next/server"; const adminRoutes = ["/admin/company", "/admin/students", "/admin/job"]; -const studentRoutes = ['/student/jobs', '/student/offCampus', '/student/onCampus', '/student/interviewExperiences', '/student/profile', '/student/resumes']; -const recruiterRoutes = ['/recruiter/jaf', '/recruiter/prevjaf']; +const studentRoutes = [ + "/student/jobs", + "/student/offCampus", + "/student/onCampus", + "/student/interviewExperiences", + "/student/profile", + "/student/resumes", +]; +const recruiterRoutes = ["/recruiter/jaf", "/recruiter/prevjaf"]; export function middleware(request: NextRequest) { const userCookie = request.cookies.get("user"); - const user = userCookie ? JSON.parse(userCookie.value) : null;; - - if (user?.role !== "ADMIN" && adminRoutes.includes(request.nextUrl.pathname) ) { + const user = userCookie ? JSON.parse(userCookie.value) : null; + + if ( + user?.role !== "ADMIN" && + adminRoutes.includes(request.nextUrl.pathname) + ) { return NextResponse.redirect(new URL("/login", request.url)); } - if (user?.role !== "STUDENT" && studentRoutes.includes(request.nextUrl.pathname) ) { + if ( + user?.role !== "STUDENT" && + studentRoutes.includes(request.nextUrl.pathname) + ) { return NextResponse.redirect(new URL("/login", request.url)); } - if (user?.role !== "RECRUITER" && recruiterRoutes.includes(request.nextUrl.pathname) && request.url.includes("/recruiter") ) { + if ( + user?.role !== "RECRUITER" && + recruiterRoutes.includes(request.nextUrl.pathname) && + request.url.includes("/recruiter") + ) { return NextResponse.redirect(new URL("/login", request.url)); }