Skip to content

Commit

Permalink
M3-500 Feat : 토큰이 재발급되면 secure storage에 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
koomin1227 committed Aug 8, 2024
1 parent 7e97384 commit 56c036c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
12 changes: 6 additions & 6 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 3BD2BV9TRM;
ENABLE_BITCODE = NO;
FLUTTER_BUILD_NAME = 1.0.3;
FLUTTER_BUILD_NAME = 1.0.4;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Ground Flip";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.healthcare-fitness";
Expand All @@ -511,7 +511,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.3;
MARKETING_VERSION = 1.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.m3pro.groundFlip;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -692,7 +692,7 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 3BD2BV9TRM;
ENABLE_BITCODE = NO;
FLUTTER_BUILD_NAME = 1.0.3;
FLUTTER_BUILD_NAME = 1.0.4;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Ground Flip";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.healthcare-fitness";
Expand All @@ -701,7 +701,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.3;
MARKETING_VERSION = 1.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.m3pro.groundFlip;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand All @@ -722,7 +722,7 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 3BD2BV9TRM;
ENABLE_BITCODE = NO;
FLUTTER_BUILD_NAME = 1.0.3;
FLUTTER_BUILD_NAME = 1.0.4;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Ground Flip";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.healthcare-fitness";
Expand All @@ -731,7 +731,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.3;
MARKETING_VERSION = 1.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.m3pro.groundFlip;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down
1 change: 1 addition & 0 deletions lib/controllers/map_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class MapController extends SuperController {
void trackPixels() {
_updatePixelTimer =
Timer.periodic(const Duration(seconds: 10), (timer) async {
UserManager().updateSecureStorage();
updatePixels();
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:flutter/services.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:ground_flip/service/location_service.dart';
import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart';
import 'package:kakao_flutter_sdk/kakao_flutter_sdk_common.dart';

Expand All @@ -20,6 +19,7 @@ import 'screens/policy_screen.dart';
import 'screens/setting_screen.dart';
import 'screens/sign_up_screen.dart';
import 'service/auth_service.dart';
import 'service/location_service.dart';
import 'utils/user_manager.dart';
import 'widgets/common/internet_disconnect.dart';

Expand Down
9 changes: 2 additions & 7 deletions lib/utils/dio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:get/get.dart' hide Response;
import 'package:ground_flip/utils/user_manager.dart';

import '../models/reissue_response.dart';
import '../service/auth_service.dart';
import 'user_manager.dart';

class DioService {
static final DioService _dioServices = DioService._internal();
static final String baseUrl = dotenv.env['BASE_URL']!;

// final SecureStorage secureStorage = SecureStorage();
final UserManager userManager = UserManager();

factory DioService() => _dioServices;
Expand All @@ -31,7 +30,6 @@ class DioService {
_dio.interceptors.add(
InterceptorsWrapper(
onRequest: (options, handler) async {
// final accessToken = await secureStorage.readAccessToken();
final accessToken = userManager.getAccessToken();
options.headers.addAll({
'Authorization': 'Bearer $accessToken',
Expand All @@ -52,9 +50,6 @@ class DioService {
ReissueResponse reissueResponse = await reissueToken();
userManager.setAccessToken(reissueResponse.accessToken!);
userManager.setRefreshToken(reissueResponse.refreshToken!);
// await secureStorage.writeAccessToken(reissueResponse.accessToken);
// await secureStorage
// .writeRefreshToken(reissueResponse.refreshToken);

Response<dynamic> resendResponse =
await resendRequest(dioException, reissueResponse);
Expand Down Expand Up @@ -87,13 +82,13 @@ class DioService {
}

Future<ReissueResponse> reissueToken() async {
// final refreshToken = await secureStorage.readRefreshToken();
final refreshToken = userManager.getRefreshToken();
final dio = Dio();
var response = await dio
.post("$baseUrl/auth/reissue", data: {"refreshToken": refreshToken});
ReissueResponse reissueResponse =
ReissueResponse.fromJson(response.data["data"]);
UserManager().setTokenReissued();
return reissueResponse;
}

Expand Down
16 changes: 16 additions & 0 deletions lib/utils/user_manager.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'secure_storage.dart';

class UserManager {
static final UserManager _instance = UserManager._internal();
final SecureStorage secureStorage = SecureStorage();

factory UserManager() {
return _instance;
Expand All @@ -10,11 +13,20 @@ class UserManager {
int? userId;
String? accessToken;
String? refreshToken;
bool? isTokenReissued;

void init() {
userId = null;
accessToken = null;
refreshToken = null;
isTokenReissued = null;
}

updateSecureStorage() {
if (isTokenReissued == true) {
secureStorage.writeAccessToken(accessToken);
secureStorage.writeRefreshToken(refreshToken);
}
}

void setUserId(int id) {
Expand All @@ -29,6 +41,10 @@ class UserManager {
this.refreshToken = refreshToken;
}

void setTokenReissued() {
isTokenReissued = true;
}

int? getUserId() {
return userId;
}
Expand Down

0 comments on commit 56c036c

Please sign in to comment.