Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/martishin/react-golang-jwt-oauth
React.js and Go project demonstrating the use of Google OAuth and JWT to authenticate users
https://github.com/martishin/react-golang-jwt-oauth
docker go-chi golang jwt oauth2 postgresql reactjs typescript
Last synced: about 2 months ago
JSON representation
React.js and Go project demonstrating the use of Google OAuth and JWT to authenticate users
- Host: GitHub
- URL: https://github.com/martishin/react-golang-jwt-oauth
- Owner: martishin
- Created: 2024-11-17T00:09:02.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-19T18:12:11.000Z (about 2 months ago)
- Last Synced: 2024-11-19T19:24:49.090Z (about 2 months ago)
- Topics: docker, go-chi, golang, jwt, oauth2, postgresql, reactjs, typescript
- Language: Go
- Homepage: https://oauth.martishin.com/
- Size: 79.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# React-Golang OAuth
An example project demonstrating user authentication and authorization with a React.js frontend and a Go backend. It integrates Google OAuth 2.0 for secure login and uses JWT with refresh tokens for session management.This project uses JWT tokens, for a simpler setup that uses session cookies, please check [this project](https://github.com/martishin/react-golang-goth-oauth).
[Check out the live demo here](https://oauth.martishin.com/)!
## Setup
### Prerequisites
1. Install the dependencies:
- [Docker](https://www.docker.com/products/docker-desktop)
- [Node.js and npm](https://nodejs.org/) (for the client)
- [Go](https://golang.org/) (for the server)
2. Obtain a valid **Google OAuth Client ID** and **Client Secret**:
- [Follow this guide](https://developers.google.com/identity/protocols/oauth2) to set up credentials.### Steps
1. Clone the repository:
```bash
git clone [email protected]:martishin/react-golang-jwt-oauth.git
cd react-golang-jwt-oauth
```
2. Set up environment variables YOUR_GOOGLE_APP_CLIENT_ID and YOUR_GOOGLE_APP_CLIENT_SECRET in the code
3. Start the database:
```bash
docker-compose up db
```
4. Start the server:
Open a new terminal window and navigate to the `server` directory:
```bash
cd server
```
Build and start the server:
```bash
go run main.go
```
The server should now be running on [http://localhost:8000](http://localhost:8000)5. Start the client:
Navigate to the `client` directory:
```bash
cd client
```
Install the dependencies:
```bash
npm install
```
Start the development server:```bash
npm run dev
```
The client should now be accessible at [http://localhost:5173](http://localhost:5173)### API Endpoints
| Method | Endpoint | Description |
|--------|-------------------|--------------------------------|
| POST | `/api/auth/google` | Google OAuth login |
| POST | `/api/auth/logout` | Log out and invalidate session |
| POST | `/api/auth/refresh`| Refresh access token |
| GET | `/api/user` | Get authenticated user details |## Tech Stack
- **Frontend**: React.js, Tailwind CSS
- **Backend**: Go, Chi
- **Database**: PostgreSQL
- **Auth Provider**: Google OAuth 2.0
- **Others**: Docker, JWT## License
This project is licensed under the MIT License.