Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import Navbar from "@/components/Navbar";
import Footer from "@/components/Footer";
import type { Metadata } from "next";
import Provider from "./Provider";
import { AuthProvider } from "../context/authContext";


// Metadata definition for the application
Expand All @@ -49,11 +50,13 @@ export default function RootLayout({ children}: { children: React.ReactNode, })
return (
<html lang="en">
<body>
<Provider>
<AuthProvider>
{/* <Provider> */}
<Navbar />
<main className="relative overflow-hidden">{children}</main>
<Footer />
</Provider>
{/* </Provider> */}
</AuthProvider>
</body>
</html>
);
Expand Down
3 changes: 2 additions & 1 deletion components/LoginSignupPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ const LoginSignupPopup = ({ onClose, onLoginSignupSuccess }) => {

const handleSubmit = (e) => {
e.preventDefault();
onLoginSignupSuccess();
// onLoginSignupSuccess();

};

const handleGoogleSignIn = () => {
Expand Down
6 changes: 4 additions & 2 deletions components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@


"use client";
import { useEffect, useState } from "react";
import { useContext, useEffect, useState } from "react";
import { useRouter, usePathname, useSearchParams } from 'next/navigation';
import { NAV_LINKS } from "@/constants";
import Image from "next/image";
Expand All @@ -1108,8 +1108,10 @@ import Button from "./Button";
import LoginSignupModal from "../app/login/page";
import ProfilePage from "./ProfilePage";
import AdminProfile from "./AdminProfile";
import { AuthContext } from "@/context/authContext";

const Navbar = () => {
const {dummy} = useContext(AuthContext)
const [dropdownOpen, setDropdownOpen] = useState(false);
const [isModalOpen, setIsModalOpen] = useState(false);
const [isLoggedIn, setIsLoggedIn] = useState(false);
Expand All @@ -1123,7 +1125,7 @@ const Navbar = () => {


useEffect(() => {

console.log(dummy)
const email = localStorage.getItem("currentEmail");
if(email)
{
Expand Down
99 changes: 99 additions & 0 deletions context/authContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

"use client";
import { verify } from "crypto";
import React, {createContext, useEffect, useState} from "react";

export const AuthContext = createContext()

export const AuthProvider = ({children})=>{

const [dummy, setDummy] = useState("dummy")
const [details, setDetails] = useState()

const generateOTP = async(formData)=>{
try {
const response = await fetch('http://localhost:5000/api/auth/generateOTP',{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData),
})
const data = await response.json()
console.log(data)
if(data.status == 'success'){
}else{
console.log('cant generateOTP')
}
} catch (error) {
console.log(error)
}
}

const verifyOTP = async()=>{
try {
const response = await fetch("http://localhost:5000/api/auth/verifyotp",{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData),
})
const data = await response.json()
console.log(data)
if(data.success) {
localStorage.setItem('authToken',data.authToken)
}
} catch (error) {
console.log(error)
}
}

const updateDetails = async()=>{
try {
const response = await fetch("http://localhost:5000/api/auth/updateDetails",{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData),
})
const data = await response.json()
console.log(data)
} catch (error) {
console.log(error)
}
}
const getUser = async(token)=>{
try {
const response = await fetch("http://localhost:5000/api/auth/getuser",{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'auth-token': token
},
body: JSON.stringify(formData),
})
const data = await response.json()
console.log(data)
setDetails(data)
} catch (error) {
console.log(error)
}
}



useEffect(()=>{
const token = localStorage.getItem('authToken')
if(token) {
getUser(token)
}
},[])

return(
<AuthContext.Provider value={{dummy, generateOTP, verifyOTP, updateDetails, details}}>
{children}
</AuthContext.Provider>
)
}