-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
built the sign up and login oauth google logic for the client and ser…
…ver, created an auth context to handle the authentication state, modified components using state to work with the context and created extra components and routes
- Loading branch information
Showing
28 changed files
with
1,143 additions
and
264 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,4 +4,8 @@ MONGO_URI="mongodb+srv://admin-fransco:[email protected]/ | |
CLOUDINARY_NAME='dyieuptpt' | ||
CLOUDINARY_API_KEY='413946266621849' | ||
CLOUDINARY_API_SECRET='0IizkxSpuvSPhYzgJpuHDXpuzXw' | ||
SECRET='secrecy' | ||
|
||
GOOGLE_CLIENT_ID=282292901096-6p49lpsprjgu5pa8rf1fh48sdglen2dl.apps.googleusercontent.com | ||
GOOGLE_CLIENT_SECRET=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 | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
This file was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
} | ||
|
||
.detail h1 { | ||
font-family: sans-serif; | ||
line-height: 1.1; | ||
color: #222; | ||
font-size: 3.4rem; | ||
|
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
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,64 @@ | ||
import React, { useState } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
const AuthContext = React.createContext({ | ||
isLoggedin: false, | ||
onSignUp: async (enteredData) => {}, | ||
googleSignIn: () => {}, | ||
}); | ||
|
||
export const AuthContextProvider = (props) => { | ||
const navigate = useNavigate(); | ||
const [isLoggedIn, setIsLoggedIn] = useState(false); | ||
|
||
const signup = async (enteredData) => { | ||
try { | ||
const response = await fetch("/api/signup", { | ||
method: "POST", | ||
body: JSON.stringify(enteredData), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
if (response.status === 200) { | ||
alert("successfully signed in"); | ||
setIsLoggedIn(true); | ||
} | ||
} catch (error) { | ||
console.log(error.response); | ||
} | ||
}; | ||
|
||
const googleAuth = () => { | ||
window.location.href = "http://localhost:3001/api/google"; | ||
}; | ||
|
||
const navigateHomeOnSuccess = () => { | ||
setIsLoggedIn(true); | ||
|
||
navigate("/"); | ||
}; | ||
|
||
const navigateWriteOnSuccess = () => { | ||
setIsLoggedIn(true); | ||
|
||
navigate("/write"); | ||
}; | ||
|
||
return ( | ||
<AuthContext.Provider | ||
value={{ | ||
isLoggedin: isLoggedIn, | ||
onSignUp: signup, | ||
googleSignIn: googleAuth, | ||
navigateHome: navigateHomeOnSuccess, | ||
navigateWrite: navigateWriteOnSuccess, | ||
}} | ||
> | ||
{props.children} | ||
</AuthContext.Provider> | ||
); | ||
}; | ||
|
||
export default AuthContext; |
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
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
Oops, something went wrong.