From 48e625dcaf772e90440408739bd1fc3918146a5f Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 13:59:47 +0900 Subject: [PATCH 01/13] =?UTF-8?q?M3-181=20Feat=20:=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=95=B1=EB=B0=94=EC=97=90=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=B2=84=ED=8A=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/widgets/common/app_bar.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/widgets/common/app_bar.dart b/lib/widgets/common/app_bar.dart index b4812b44..257552b6 100644 --- a/lib/widgets/common/app_bar.dart +++ b/lib/widgets/common/app_bar.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:get/get.dart'; class MapAppBar extends StatelessWidget { const MapAppBar({super.key}); @@ -44,6 +45,14 @@ class MyPageAppBar extends StatelessWidget { return AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: const Text('마이페이지'), + actions: [ + IconButton( + icon: const Icon(Icons.settings), + onPressed: () { + Get.toNamed('/setting'); + }, + ), + ], ); } } From e30e69da9df6214425519ba03e9d45a789c88ea0 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 14:37:28 +0900 Subject: [PATCH 02/13] =?UTF-8?q?M3-181=20Feat=20:=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/screens/setting_screen.dart | 50 ++++++++++++++++++++++++ lib/widgets/setting/setting_item.dart | 20 ++++++++++ lib/widgets/setting/setting_section.dart | 33 ++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 lib/screens/setting_screen.dart create mode 100644 lib/widgets/setting/setting_item.dart create mode 100644 lib/widgets/setting/setting_section.dart diff --git a/lib/screens/setting_screen.dart b/lib/screens/setting_screen.dart new file mode 100644 index 00000000..11b17349 --- /dev/null +++ b/lib/screens/setting_screen.dart @@ -0,0 +1,50 @@ +import 'package:flutter/material.dart'; + +import '../widgets/setting/setting_item.dart'; +import '../widgets/setting/setting_section.dart'; + +class SettingScreen extends StatelessWidget { + const SettingScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + backgroundColor: Theme.of(context).colorScheme.inversePrimary, + title: const Text('설정'), + ), + body: ListView( + children: [ + SettingsSection( + title: '설정', + items: [ + SettingsItem(title: '수령 정보 설정'), + SettingsItem(title: '알림 설정'), + SettingsItem(title: '맵 설정'), + SettingsItem(title: '실험실'), + SettingsItem(title: '앱 최적화'), + SettingsItem(title: 'App Store 리뷰 남기기'), + ], + ), + SettingsSection( + title: '가이드', + items: [ + SettingsItem(title: '공지사항'), + SettingsItem(title: '플레이 가이드'), + SettingsItem(title: '고객 문의 및 개선 요청'), + ], + ), + SettingsSection( + title: '기타', + items: [ + SettingsItem(title: '서비스이용약관'), + SettingsItem( + title: '로그아웃', + ), + ], + ), + ], + ), + ); + } +} diff --git a/lib/widgets/setting/setting_item.dart b/lib/widgets/setting/setting_item.dart new file mode 100644 index 00000000..5b756b28 --- /dev/null +++ b/lib/widgets/setting/setting_item.dart @@ -0,0 +1,20 @@ +import 'package:flutter/material.dart'; + +class SettingsItem extends StatelessWidget { + final String title; + final VoidCallback? onTap; + + const SettingsItem({required this.title, this.onTap, super.key}); + + @override + Widget build(BuildContext context) { + return ListTile( + title: Text( + title, + style: const TextStyle(color: Colors.black), + ), + trailing: const Icon(Icons.arrow_forward_ios, color: Colors.black), + onTap: onTap, + ); + } +} diff --git a/lib/widgets/setting/setting_section.dart b/lib/widgets/setting/setting_section.dart new file mode 100644 index 00000000..041b0611 --- /dev/null +++ b/lib/widgets/setting/setting_section.dart @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; + +import 'setting_item.dart'; + +class SettingsSection extends StatelessWidget { + final String title; + final List items; + + SettingsSection({required this.title, required this.items, super.key}); + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.all(16.0), + child: Text( + title, + style: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + color: Colors.black, + ), + ), + ), + Column( + children: items.map((item) => item).toList(), + ), + ], + ); + } +} From 72264f3fd06025b8b320864ead0edca15d7d6bde Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 14:41:30 +0900 Subject: [PATCH 03/13] =?UTF-8?q?M3-181=20Style=20:=20=EA=B3=B5=EB=B0=B1?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controllers/my_page_controller.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/controllers/my_page_controller.dart b/lib/controllers/my_page_controller.dart index 0ed2b33b..58073fc9 100644 --- a/lib/controllers/my_page_controller.dart +++ b/lib/controllers/my_page_controller.dart @@ -30,11 +30,11 @@ class MyPageController extends GetxController { return currentUserInfo.value.communityName ?? "-"; } - int getCurrentUserPixel(){ + int getCurrentUserPixel() { return userPixelCount.value.currentPixelCount ?? 0; } - int getAccumulateUserPixel(){ + int getAccumulateUserPixel() { return userPixelCount.value.accumulatePixelCount ?? 0; } } From 56a2f1fb4c935bae6030b209906ce5e98ceffe7f Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 14:42:37 +0900 Subject: [PATCH 04/13] =?UTF-8?q?M3-181=20Feat=20:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83=20=EB=B2=84=ED=8A=BC=EC=9D=84=20=EB=88=84?= =?UTF-8?q?=EB=A5=B4=EB=A9=B4=20=EB=A1=9C=EA=B7=B8=EC=95=84=EC=9B=83=20?= =?UTF-8?q?=EC=8B=9C=ED=82=A4=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controllers/setting_controller.dart | 12 ++++++++++++ lib/main.dart | 2 ++ lib/screens/setting_screen.dart | 7 +++++++ 3 files changed, 21 insertions(+) create mode 100644 lib/controllers/setting_controller.dart diff --git a/lib/controllers/setting_controller.dart b/lib/controllers/setting_controller.dart new file mode 100644 index 00000000..692d17e0 --- /dev/null +++ b/lib/controllers/setting_controller.dart @@ -0,0 +1,12 @@ +import 'package:get/get.dart'; + +import '../service/auth_service.dart'; + +class SettingController extends GetxController { + final AuthService authService = AuthService(); + + logout() async { + await authService.logout(); + Get.offAllNamed('/login'); + } +} diff --git a/lib/main.dart b/lib/main.dart index 59ad846a..c0c82fd4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,6 +6,7 @@ import 'package:kakao_flutter_sdk/kakao_flutter_sdk_common.dart'; import 'screens/login_screen.dart'; import 'screens/main_screen.dart'; +import 'screens/setting_screen.dart'; import 'service/auth_service.dart'; Future main() async { @@ -41,6 +42,7 @@ class MyApp extends StatelessWidget { getPages: [ GetPage(name: '/main', page: () => const MainScreen()), GetPage(name: '/login', page: () => const LoginScreen()), + GetPage(name: '/setting', page: () => const SettingScreen()), ], ); } diff --git a/lib/screens/setting_screen.dart b/lib/screens/setting_screen.dart index 11b17349..cdfbf280 100644 --- a/lib/screens/setting_screen.dart +++ b/lib/screens/setting_screen.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import '../controllers/setting_controller.dart'; import '../widgets/setting/setting_item.dart'; import '../widgets/setting/setting_section.dart'; @@ -8,6 +10,8 @@ class SettingScreen extends StatelessWidget { @override Widget build(BuildContext context) { + SettingController settingController = Get.put(SettingController()); + return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, @@ -40,6 +44,9 @@ class SettingScreen extends StatelessWidget { SettingsItem(title: '서비스이용약관'), SettingsItem( title: '로그아웃', + onTap: () { + settingController.logout(); + }, ), ], ), From ab802885fda5bc7e689496d554a44b1b85d138b4 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 14:51:36 +0900 Subject: [PATCH 05/13] =?UTF-8?q?M3-181=20Feat=20:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83=20=EB=B2=84=ED=8A=BC=EC=9D=84=20=EB=88=8C?= =?UTF-8?q?=EB=A0=80=EC=9D=84=EB=95=8C=20=EB=A1=9C=EA=B7=B8=EC=95=84?= =?UTF-8?q?=EC=9B=83=20=ED=95=A0=20=EA=B1=B4=EC=A7=80=20=EB=AC=BC=EC=96=B4?= =?UTF-8?q?=EB=B3=B4=EB=8A=94=20=EB=AA=A8=EB=8B=AC=20=EC=B0=BD=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controllers/setting_controller.dart | 28 +++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/controllers/setting_controller.dart b/lib/controllers/setting_controller.dart index 692d17e0..ddd83d9a 100644 --- a/lib/controllers/setting_controller.dart +++ b/lib/controllers/setting_controller.dart @@ -1,3 +1,4 @@ +import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../service/auth_service.dart'; @@ -6,7 +7,30 @@ class SettingController extends GetxController { final AuthService authService = AuthService(); logout() async { - await authService.logout(); - Get.offAllNamed('/login'); + _showLogoutDialog(); + } + + void _showLogoutDialog() { + Get.dialog( + AlertDialog( + title: Text('로그아웃 하시겠습니까?'), + actions: [ + TextButton( + child: Text('아니오'), + onPressed: () async { + await authService.logout(); + Get.back(); + }, + ), + TextButton( + child: Text('예'), + onPressed: () async { + await authService.logout(); + Get.offAllNamed('/login'); + }, + ), + ], + ), + ); } } From db25e7aad21b1f8b3c2c56f6bf5ed87330720ec9 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 15:02:36 +0900 Subject: [PATCH 06/13] =?UTF-8?q?M3-181=20Feat=20:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83=20=EC=8B=9C=20=EC=84=9C=EB=B2=84=EC=97=90=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=95=84=EC=9B=83=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EC=A0=84=EC=86=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 서버에서 실패해도 클라이언트에서는 성공하게 하였다. --- lib/service/auth_service.dart | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/service/auth_service.dart b/lib/service/auth_service.dart index fecd94cb..646240b4 100644 --- a/lib/service/auth_service.dart +++ b/lib/service/auth_service.dart @@ -22,10 +22,20 @@ class AuthService { return _instance; } - logout() { - secureStorage.deleteAccessToken(); - secureStorage.deleteRefreshToken(); - UserManager().init(); + logout() async { + try { + await postLogout(); + } catch (e) { + debugPrint('Error during logout: $e'); + } finally { + await secureStorage.deleteAccessToken(); + await secureStorage.deleteRefreshToken(); + UserManager().init(); + } + } + + postLogout() async { + await dio.post('/auth/logout'); } Future isLogin() async { From 87edd4a0276eeabb2f0076c3c0935ed75381f018 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 16:08:02 +0900 Subject: [PATCH 07/13] =?UTF-8?q?M3-181=20Feat=20:=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/widgets/map/pixel_owner_info.dart | 2 +- lib/widgets/map/visited_user_list_view.dart | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/widgets/map/pixel_owner_info.dart b/lib/widgets/map/pixel_owner_info.dart index 226189f4..e55c3b50 100644 --- a/lib/widgets/map/pixel_owner_info.dart +++ b/lib/widgets/map/pixel_owner_info.dart @@ -21,7 +21,7 @@ class PixelOwnerInfo extends StatelessWidget { fit: BoxFit.cover, ) : Image.asset( - 'assets/default_profile_image.png', + 'assets/images/default_profile_image.png', width: 50, height: 50, ), diff --git a/lib/widgets/map/visited_user_list_view.dart b/lib/widgets/map/visited_user_list_view.dart index c9a96c68..43cb2ea0 100644 --- a/lib/widgets/map/visited_user_list_view.dart +++ b/lib/widgets/map/visited_user_list_view.dart @@ -36,7 +36,7 @@ class VisitedUserListView extends StatelessWidget { fit: BoxFit.cover, ) : Image.asset( - 'assets/default_profile_image.png', + 'assets/images/default_profile_image.png', width: 50, height: 50, ), @@ -47,9 +47,10 @@ class VisitedUserListView extends StatelessWidget { Text( visitList[index].nickname!, style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold, - color: Colors.white,), + fontSize: 20, + fontWeight: FontWeight.bold, + color: Colors.white, + ), ), ], ), From 0e31ecf030fbbc9792e38d9faaf33055f146c163 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 16:14:58 +0900 Subject: [PATCH 08/13] =?UTF-8?q?M3-181=20Feat=20:=20defaultUserId=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/widgets/pixel.dart | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/widgets/pixel.dart b/lib/widgets/pixel.dart index 2c524a38..b7cc7309 100644 --- a/lib/widgets/pixel.dart +++ b/lib/widgets/pixel.dart @@ -7,6 +7,7 @@ import '../models/individual_history_pixel.dart'; import '../models/individual_history_pixel_info.dart'; import '../models/individual_mode_pixel.dart'; import '../models/individual_mode_pixel_info.dart'; +import '../utils/user_manager.dart'; import 'map/individual_history_pixel_info_bottom_sheet.dart'; import 'map/individual_mode_pixel_info_bottom_sheet.dart'; @@ -14,8 +15,6 @@ class Pixel extends Polygon { static const double latPerPixel = 0.000724; static const double lonPerPixel = 0.000909; - static const int defaultUserId = 2; - final int x; final int y; final int pixelId; @@ -89,8 +88,8 @@ class Pixel extends Polygon { strokeWidth: 1, onTap: (int pixelId) async { IndividualHistoryPixelInfo pixelInfo = - await Get.find() - .getIndividualHistoryPixelInfo(pixelId, defaultUserId); + await Get.find().getIndividualHistoryPixelInfo( + pixelId, UserManager().getUserId()!); Get.bottomSheet( IndividualHistoryPixelInfoBottomSheet(pixelInfo: pixelInfo), From 0a0c60890affd6e2708d88774094938904bf1bac Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 16:27:33 +0900 Subject: [PATCH 09/13] =?UTF-8?q?M3-181=20Feat=20:=20model=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controllers/login_controller.dart | 2 +- lib/models/auth_response.dart | 6 +++--- lib/models/reissue_response.dart | 14 ++++++++++++++ lib/service/auth_service.dart | 8 ++++---- 4 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 lib/models/reissue_response.dart diff --git a/lib/controllers/login_controller.dart b/lib/controllers/login_controller.dart index bcab1a61..7b7023b7 100644 --- a/lib/controllers/login_controller.dart +++ b/lib/controllers/login_controller.dart @@ -9,7 +9,7 @@ class LoginController extends GetxController { loginWithKakao() async { try { - AuthResponse authResponse = await authService.loginWithKakao(); + LoginResponse authResponse = await authService.loginWithKakao(); if (authResponse.isSignUp!) { Get.toNamed('/signup'); } else { diff --git a/lib/models/auth_response.dart b/lib/models/auth_response.dart index 85a5fdc3..547607e6 100644 --- a/lib/models/auth_response.dart +++ b/lib/models/auth_response.dart @@ -1,15 +1,15 @@ -class AuthResponse { +class LoginResponse { String? accessToken; String? refreshToken; bool? isSignUp; - AuthResponse({ + LoginResponse({ this.accessToken, this.refreshToken, this.isSignUp, }); - AuthResponse.fromJson(Map json) { + LoginResponse.fromJson(Map json) { accessToken = json['accessToken']; refreshToken = json['refreshToken']; isSignUp = json['isSignUp']; diff --git a/lib/models/reissue_response.dart b/lib/models/reissue_response.dart new file mode 100644 index 00000000..8a96a61e --- /dev/null +++ b/lib/models/reissue_response.dart @@ -0,0 +1,14 @@ +class ReissueResponse { + String? accessToken; + String? refreshToken; + + ReissueResponse({ + this.accessToken, + this.refreshToken, + }); + + ReissueResponse.fromJson(Map json) { + accessToken = json['accessToken']; + refreshToken = json['refreshToken']; + } +} diff --git a/lib/service/auth_service.dart b/lib/service/auth_service.dart index 646240b4..9c3e2410 100644 --- a/lib/service/auth_service.dart +++ b/lib/service/auth_service.dart @@ -51,22 +51,22 @@ class AuthService { loginWithKakao() async { String accessToken = await _getKakaoAccessToken(); - AuthResponse authResponse = await postKakaoLogin(accessToken); + LoginResponse authResponse = await postKakaoLogin(accessToken); await _saveTokens(authResponse); return authResponse; } - Future _saveTokens(AuthResponse authResponse) async { + Future _saveTokens(LoginResponse authResponse) async { await secureStorage.writeAccessToken(authResponse.accessToken); await secureStorage.writeRefreshToken(authResponse.refreshToken); UserManager().setUserId(_extractUserIdFromToken(authResponse.accessToken!)); } - Future postKakaoLogin(String accessToken) async { + Future postKakaoLogin(String accessToken) async { try { var response = await dio .post('/auth/kakao/login', data: {"accessToken": accessToken}); - return AuthResponse.fromJson(response.data["data"]); + return LoginResponse.fromJson(response.data["data"]); } catch (error) { throw Exception("로그인 실패"); } From 9ad2a164f795cdf33de514ace46f74c4def21366 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 16:28:07 +0900 Subject: [PATCH 10/13] =?UTF-8?q?M3-181=20Feat=20:=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EC=9E=AC=EB=B0=9C=EA=B8=89=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils/dio_service.dart | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/utils/dio_service.dart b/lib/utils/dio_service.dart index 64c29839..ee7d5217 100644 --- a/lib/utils/dio_service.dart +++ b/lib/utils/dio_service.dart @@ -3,9 +3,8 @@ import 'dart:io'; 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 '../service/auth_service.dart'; +import '../models/reissue_response.dart'; import 'secure_storage.dart'; class DioService { @@ -42,13 +41,31 @@ class DioService { onError: ( DioException dioException, ErrorInterceptorHandler errorInterceptorHandler, - ) { + ) async { if (dioException.response?.statusCode == HttpStatus.unauthorized) { - AuthService().logout(); - Get.offAllNamed('/login'); + final refreshToken = await secureStorage.readRefreshToken(); + final dio = Dio(); + var response = await dio.post("$baseUrl/auth/reissue", + data: {"refreshToken": refreshToken}); + ReissueResponse reissueResponse = + ReissueResponse.fromJson(response.data["data"]); + + await secureStorage.writeAccessToken(reissueResponse.accessToken); + await secureStorage.writeRefreshToken(reissueResponse.refreshToken); + + final options = dioException.requestOptions; + options.headers.addAll({ + 'Authorization': 'Bearer ${reissueResponse.accessToken}', + }); + var response2 = await _dio.fetch(options); + errorInterceptorHandler.resolve(response2); + print('-------------refresh---------------'); + // AuthService().logout(); + // Get.offAllNamed('/login'); + } else { + logError(dioException); + return errorInterceptorHandler.next(dioException); } - logError(dioException); - return errorInterceptorHandler.next(dioException); }, ), ); From b5176a9d72ac1ae0be7f01bdac7942babd765feb Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 16:49:19 +0900 Subject: [PATCH 11/13] =?UTF-8?q?M3-181=20Feat=20:=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EC=9E=AC=EB=B0=9C=EA=B8=89=20=EA=B5=AC=ED=98=84=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils/dio_service.dart | 54 +++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/lib/utils/dio_service.dart b/lib/utils/dio_service.dart index ee7d5217..66cf4f2b 100644 --- a/lib/utils/dio_service.dart +++ b/lib/utils/dio_service.dart @@ -3,8 +3,10 @@ import 'dart:io'; 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 '../models/reissue_response.dart'; +import '../service/auth_service.dart'; import 'secure_storage.dart'; class DioService { @@ -43,25 +45,20 @@ class DioService { ErrorInterceptorHandler errorInterceptorHandler, ) async { if (dioException.response?.statusCode == HttpStatus.unauthorized) { - final refreshToken = await secureStorage.readRefreshToken(); - final dio = Dio(); - var response = await dio.post("$baseUrl/auth/reissue", - data: {"refreshToken": refreshToken}); - ReissueResponse reissueResponse = - ReissueResponse.fromJson(response.data["data"]); + try { + ReissueResponse reissueResponse = await reissueToken(); + await secureStorage.writeAccessToken(reissueResponse.accessToken); + await secureStorage + .writeRefreshToken(reissueResponse.refreshToken); - await secureStorage.writeAccessToken(reissueResponse.accessToken); - await secureStorage.writeRefreshToken(reissueResponse.refreshToken); - - final options = dioException.requestOptions; - options.headers.addAll({ - 'Authorization': 'Bearer ${reissueResponse.accessToken}', - }); - var response2 = await _dio.fetch(options); - errorInterceptorHandler.resolve(response2); - print('-------------refresh---------------'); - // AuthService().logout(); - // Get.offAllNamed('/login'); + Response resendResponse = + await resendRequest(dioException, reissueResponse); + errorInterceptorHandler.resolve(resendResponse); + debugPrint('-------------refresh---------------'); + } catch (err) { + AuthService().logout(); + Get.offAllNamed('/login'); + } } else { logError(dioException); return errorInterceptorHandler.next(dioException); @@ -71,6 +68,27 @@ class DioService { ); } + Future> resendRequest( + DioException dioException, ReissueResponse reissueResponse) async { + final options = dioException.requestOptions; + final dio = Dio(); + options.headers.addAll({ + 'Authorization': 'Bearer ${reissueResponse.accessToken}', + }); + var response = await dio.fetch(options); + return response; + } + + Future reissueToken() async { + final refreshToken = await secureStorage.readRefreshToken(); + final dio = Dio(); + var response = await dio + .post("$baseUrl/auth/reissue", data: {"refreshToken": refreshToken}); + ReissueResponse reissueResponse = + ReissueResponse.fromJson(response.data["data"]); + return reissueResponse; + } + Dio getDio() { return _dio; } From 65cc8e522e1b63ccb66761afee0be45622d00ea0 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 19:47:35 +0900 Subject: [PATCH 12/13] =?UTF-8?q?M3-181=20Style=20:=20=EC=BD=A4=EB=A7=88?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils/dio_service.dart | 4 +++- lib/widgets/pixel.dart | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/utils/dio_service.dart b/lib/utils/dio_service.dart index 66cf4f2b..2d471f37 100644 --- a/lib/utils/dio_service.dart +++ b/lib/utils/dio_service.dart @@ -69,7 +69,9 @@ class DioService { } Future> resendRequest( - DioException dioException, ReissueResponse reissueResponse) async { + DioException dioException, + ReissueResponse reissueResponse, + ) async { final options = dioException.requestOptions; final dio = Dio(); options.headers.addAll({ diff --git a/lib/widgets/pixel.dart b/lib/widgets/pixel.dart index b7cc7309..986bedf5 100644 --- a/lib/widgets/pixel.dart +++ b/lib/widgets/pixel.dart @@ -89,7 +89,9 @@ class Pixel extends Polygon { onTap: (int pixelId) async { IndividualHistoryPixelInfo pixelInfo = await Get.find().getIndividualHistoryPixelInfo( - pixelId, UserManager().getUserId()!); + pixelId, + UserManager().getUserId()!, + ); Get.bottomSheet( IndividualHistoryPixelInfoBottomSheet(pixelInfo: pixelInfo), From d978ff05a8f5a41dd3757fa9dd054d8517eef170 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Thu, 11 Jul 2024 19:49:24 +0900 Subject: [PATCH 13/13] =?UTF-8?q?M3-181=20Style=20:=20=EB=B9=88=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/screens/search_group.dart | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 lib/screens/search_group.dart diff --git a/lib/screens/search_group.dart b/lib/screens/search_group.dart deleted file mode 100644 index 139597f9..00000000 --- a/lib/screens/search_group.dart +++ /dev/null @@ -1,2 +0,0 @@ - -