https://github.com/dashroshan/mern-google-auth
🔐 Boilerplate code to implement google authentication with MERN stack
https://github.com/dashroshan/mern-google-auth
authorization google-authentication mern
Last synced: about 1 year ago
JSON representation
🔐 Boilerplate code to implement google authentication with MERN stack
- Host: GitHub
- URL: https://github.com/dashroshan/mern-google-auth
- Owner: dashroshan
- Created: 2022-09-02T07:22:17.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-21T16:24:23.000Z (over 3 years ago)
- Last Synced: 2025-02-12T21:17:31.771Z (over 1 year ago)
- Topics: authorization, google-authentication, mern
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Install dependencies
```
npm install
```
config.env file inside config directory
```
PORT = 4000
MONGO_URI = mongodb://localhost:27017/google
GOOGLE_CLIENT_ID = xxxxx.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET = xxxxxxxxxxxxxxxxxxxxxxxxxxxx
CALLBACK_URL = /auth/google/callback
```
example react index.js file (running on port 3000)
```
import './App.css';
import axios from "axios";
function App() {
const checkLogin = async () => {
try {
const res = await axios.get("http://localhost:4000/auth/check", { withCredentials: true });
console.log(JSON.stringify(res.data));
}
catch (err) {
console.log(err);
}
}
const logOut = async () => {
try {
const res = await axios.get("http://localhost:4000/auth/logout", { withCredentials: true });
console.log(JSON.stringify(res.data));
}
catch (err) {
console.log(err);
}
}
return (
);
}
export default App;
```