This Flutter project demonstrates handling authentication processes such as login, signup, OTP verification, and automatic token refresh using the Dio HTTP client, with secure storage management using Flutter Secure Storage.
- User Authentication (Login, Signup)
- OTP Verification
- Automatic Token Refresh using Interceptors
- Secure Token Storage
- Login: Use
ApiService().login(email, password)
to authenticate users. - Signup: Use
ApiService().signUp(name, email, password)
to register new users. - Verify OTP: Use
ApiService().verifyOtp(email, otp)
for OTP verification.
- Securely Store Tokens: Use
SecureStorageManager.writeData('accessToken', token)
to store tokens securely. - Read Tokens: Use
SecureStorageManager.readData('accessToken')
to retrieve tokens securely.
Ensure all API requests are authenticated using the access token retrieved from secure storage:
Future<Response> getProductByToken() async {
final token = await SecureStorageManager.readData('accessToken');
final response = await _dio.get('/product/1',
options: Options(headers: {'Authorization': 'Bearer $token'}));
return response;
}
The RefreshTokenInterceptor
automatically handles token expiration by refreshing the token and retrying the original request seamlessly when encountering 401 or 403 errors.
intain secure sessions across multiple services or APIs.
Contributions to the project are welcome! Please fork the repository and submit a pull request with your features or fixes.
If you encounter any issues while using this project, please open an issue in the repository with a detailed description of the problem, steps to reproduce it, and the expected behavior. We appreciate your contributions to improving this project.
For any questions or feedback, please reach out via email: [email protected]