The frontend service (Flutter) receives the response from the backend.
If the login was successful, the frontend service can store both the JWT token and the refresh token locally (e.g., in a secure storage) for subsequent authenticated requests.
When the JWT token expires (usually after a short period), the frontend service can use the refresh token to request a new JWT token from the backend without requiring the user to log in again.
The frontend service sends a POST request to the backend service with the refresh token to obtain a new JWT token.
Frontend request for token refresh:
POST /api/refresh_token
{
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
The backend service (Java) receives the refresh token request from the frontend.
The backend service validates the refresh token and checks if it's still valid and associated with a valid user.
If the refresh token is valid, the backend service generates a new JWT token and returns it along with a success response to the frontend.
With the inclusion of the refresh token, the frontend can maintain an active user session even after the JWT token expires, providing a smoother user experience without frequent logins.
User enters email and password and clicks login on the Flutter app.
The frontend service (Flutter) collects the login information (email and password) from the user's input.
The frontend service sends a POST request to the backend service (Java) with the login information in the request body.
Frontend request:
The backend service (Java) receives the login request from the frontend.
The backend service checks if the user with the provided email exists in the database.
If the user exists, the backend service then verifies if the provided password matches the one stored in the database for that user.
If the email and password are correct, the backend service generates a JSON Web Token (JWT) for the user and also creates a refresh token.
The backend service returns both the JWT and the refresh token along with a success response to the frontend.
Backend response (on successful login):
The frontend service (Flutter) receives the response from the backend.
If the login was successful, the frontend service can store both the JWT token and the refresh token locally (e.g., in a secure storage) for subsequent authenticated requests.
When the JWT token expires (usually after a short period), the frontend service can use the refresh token to request a new JWT token from the backend without requiring the user to log in again.
The frontend service sends a POST request to the backend service with the refresh token to obtain a new JWT token.
Frontend request for token refresh:
The backend service (Java) receives the refresh token request from the frontend.
The backend service validates the refresh token and checks if it's still valid and associated with a valid user.
If the refresh token is valid, the backend service generates a new JWT token and returns it along with a success response to the frontend.
Backend response (on successful token refresh):
Backend response (on failed token refresh):
With the inclusion of the refresh token, the frontend can maintain an active user session even after the JWT token expires, providing a smoother user experience without frequent logins.