https://github.com/coderhs/rails-api-only-devise-jwt-example-app
Example Rails 8 App Only app that uses Devise JWT for authentication
https://github.com/coderhs/rails-api-only-devise-jwt-example-app
Last synced: 9 months ago
JSON representation
Example Rails 8 App Only app that uses Devise JWT for authentication
- Host: GitHub
- URL: https://github.com/coderhs/rails-api-only-devise-jwt-example-app
- Owner: coderhs
- Created: 2025-04-09T15:02:30.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-04-21T23:14:22.000Z (9 months ago)
- Last Synced: 2025-05-08T01:48:24.659Z (9 months ago)
- Language: Ruby
- Size: 50.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Example App: Rails 8 in API Only Mode, with Devise JWT for authentication
This is an example of a Rails 8 API-only app that uses Devise JWT for authentication.
# How to get started
```sh
git clone git@github.com:coderhs/rails-api-only-devise-jwt-example-app.git
```
Create the `credentials.yml.enc` file:
```sh
EDITOR="vim" rails credentials:edit
```
Copy the contents from c`redentials.example.yml` into your new file:
```yml
secret_key_base:
devise:
jwt_secret_key:
```
Fill in both fields with secret tokens, which you can generate using the command `rails secret`
Save and close vim
## API end point / testing
### Register a User
```sh
curl -i -X POST http://localhost:3000/signup \
-H "Content-Type: application/json" \
-d '{"user": {"email": "test@example.com", "password": "password"}}'
```
You will receive the JWT token in the response.
### Log in a User
```sh
curl -i -X POST http://localhost:3000/login \
-H "Content-Type: application/json" \
-d '{"user": {"email": "test@example.com", "password": "password"}}'
```
The JWT token will be returned in the response headers.
### Accessing a Protected API Endpoint
#### Without token
```sh
curl 'http://localhost:3000/secret'
```
Response
```json
{"error":"You need to sign in or sign up before continuing."}
```
#### With token
```sh
curl 'http://localhost:3000/secret' -H 'Authorization: Bearer '
```
Response
😉 Try and find out