-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Dat-TG/milestone-3
Milestone 3
- Loading branch information
Showing
178 changed files
with
3,165 additions
and
1,414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="facebook_app_id">868392621641182</string> | ||
<string name="facebook_client_token">dd6fd3999d5fe99d773f8a8e9e877f7a</string> | ||
</resources> |
1 change: 1 addition & 0 deletions
1
...ient_secret_157247432892-sqk0gq6q94c2be14uq0v23qfmol34pno.apps.googleusercontent.com.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"installed":{"client_id":"157247432892-sqk0gq6q94c2be14uq0v23qfmol34pno.apps.googleusercontent.com","project_id":"lettutor-407509","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:let_tutor/core/interceptors/auth_interceptor.dart'; | ||
import 'package:let_tutor/core/utils/constants.dart'; | ||
|
||
class DioClient { | ||
static Dio getInstance() { | ||
final Dio dio = Dio(BaseOptions( | ||
baseUrl: AppConstants.baseUrl, | ||
connectTimeout: const Duration(seconds: 30), | ||
receiveTimeout: const Duration(seconds: 30), | ||
)); | ||
|
||
dio.interceptors.add(AuthInterceptor(dio)); | ||
|
||
return dio; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:let_tutor/injection_container.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
class AuthInterceptor extends Interceptor { | ||
final Dio dio; | ||
|
||
AuthInterceptor(this.dio); | ||
|
||
@override | ||
Future<void> onRequest( | ||
RequestOptions options, | ||
RequestInterceptorHandler handler, | ||
) async { | ||
// Retrieve token from wherever it's stored (e.g., SharedPreferences) | ||
final String? token = sl<SharedPreferences>() | ||
.getString('access-token'); // Implement this function to get the token | ||
|
||
if (token != null) { | ||
options.headers['Authorization'] = 'Bearer $token'; | ||
} | ||
|
||
print( | ||
'Request: ${options.method} ${options.headers} ${options.path} ${options.queryParameters}'); | ||
|
||
return handler.next(options); | ||
} | ||
|
||
@override | ||
Future<void> onResponse( | ||
Response response, ResponseInterceptorHandler handler) async { | ||
print( | ||
'Response: ${response.statusCode} ${response.headers} ${response.data}'); | ||
return handler.next(response); | ||
} | ||
|
||
@override | ||
Future<void> onError( | ||
DioException err, ErrorInterceptorHandler handler) async { | ||
print('Error: ${err.response?.statusCode} ${err.response!.headers}'); | ||
if (err.response?.statusCode == 401) { | ||
// Refresh token | ||
final String? refreshToken = sl<SharedPreferences>().getString( | ||
'refresh-token'); // Implement this function to get the token | ||
|
||
if (refreshToken != null) { | ||
final response = await dio.post( | ||
'/auth/refresh-token', | ||
data: { | ||
'refreshToken': refreshToken, | ||
'timezone': DateTime.now().timeZoneOffset.inHours, | ||
}, | ||
); | ||
if (response.statusCode == 200) { | ||
// Save new tokens | ||
final data = response.data; | ||
sl<SharedPreferences>().setString( | ||
'access-token', response.data['tokens']['access']['token']); | ||
sl<SharedPreferences>() | ||
.setString('refresh-token', data['tokens']['refresh']['token']); | ||
|
||
// Retry | ||
RequestOptions options = err.requestOptions; | ||
final retryResponse = await dio.request(err.requestOptions.path, | ||
options: Options( | ||
method: options.method, | ||
headers: options.headers, | ||
extra: options.extra, | ||
contentType: options.contentType, | ||
responseType: options.responseType, | ||
validateStatus: options.validateStatus, | ||
receiveTimeout: options.receiveTimeout, | ||
sendTimeout: options.sendTimeout, | ||
followRedirects: options.followRedirects, | ||
maxRedirects: options.maxRedirects, | ||
requestEncoder: options.requestEncoder, | ||
responseDecoder: options.responseDecoder, | ||
listFormat: options.listFormat, | ||
)); | ||
return handler.resolve(retryResponse); | ||
} | ||
} | ||
} | ||
|
||
return handler.next(err); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.