Json web token (jwt) authentication and blacklist for invalid tokens + Example app (Android, iOS and Web)
This code is a dockerized example of a login API service with Json web token (JWT) and a simple app for Android, iOS and web with React Native and React Native Web.
The API service allows logging in, retrieving logged user data and logging out.
- When logging out the token is included in a table (blacklist)
- There is a cron configured on the
server > .env > CLEAR_BLACK_LIST
that erases the already peeked tokens
Observation: Application under construction (No login form)
Install Xcode and Android studio and follow the react native instructions
- REST API backend is powered by Express.js, Node.js with Typescript and PostgreSQL database
- The app is developed in React Native and React Native Web
- Docker is required to run the application (Note: My docker version - 4.5.1)
- To start go to the project root directory and run the following command in your terminal
docker-compose up -d
- After completing open the browser and access:
localhost:3000
Login - HTTP /POST
- cURL
curl --location --request POST 'localhost:3001/api/auth/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "admin.admin@gmail.com",
"password": "123456"
}'
Get user data - HTTP /GET
- cURL
curl --location --request GET 'localhost:3001/api/user' \
--header 'authorization: ${TOKEN}'
Get all users - HTTP /GET
- cURL
curl --location --request GET 'localhost:3001/api/user/all' \
--header 'authorization: ${TOKEN}'
Logout - HTTP /GET
- cURL
curl --location --request GET 'localhost:3001/api/auth/logout' \
--header 'authorization: ${TOKEN}'