Skip to content

Commit

Permalink
Fix: newest main branch apply
Browse files Browse the repository at this point in the history
  • Loading branch information
ybmin committed Sep 8, 2023
1 parent 4783ed0 commit 77741da
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 56 deletions.
11 changes: 0 additions & 11 deletions lib/constants/constants.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import "package:dio/dio.dart";
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:taxiapp/utils/remoteConfigController.dart';

String address = RemoteConfigController().backUrl;

final BaseOptions connectionOptions = BaseOptions(
baseUrl: address,
connectTimeout: const Duration(seconds: 150),
receiveTimeout: const Duration(seconds: 130),
);

//아래의 상수들은 피그마 기준 상의 패딩 픽셀과는 차이를 두고 있지만,
//이는 모바일 환경상 웹뷰와 같은 간격을 제시하기 위해 설정한 값들입니다.
Expand Down
6 changes: 4 additions & 2 deletions lib/utils/fcmToken.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import "package:dio/dio.dart";
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:taxiapp/constants/constants.dart';
import 'package:taxiapp/utils/remoteConfigController.dart';

class FcmToken {
String token;

static FcmToken? _instance;

final Dio _dio = Dio(connectionOptions);
final Dio _dio = Dio();

FcmToken._internal({required this.token});

Expand All @@ -32,6 +32,7 @@ class FcmToken {
String get fcmToken => token;

Future<bool> registerToken(String accessToken) async {
_dio.options.baseUrl = RemoteConfigController().backUrl;
return _dio.post("auth/app/device", data: {
"accessToken": accessToken,
"deviceToken": token,
Expand All @@ -43,6 +44,7 @@ class FcmToken {
}

Future<bool> removeToken(String accessToken) async {
_dio.options.baseUrl = RemoteConfigController().backUrl;
return _dio.delete("auth/app/device", data: {
"accessToken": accessToken,
"deviceToken": token,
Expand Down
8 changes: 3 additions & 5 deletions lib/utils/pushHandler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ Future<void> handleMessage(RemoteMessage message) async {
var details =
NotificationDetails(android: androidNotiDetails, iOS: iOSNotiDetails);

if (message.data != null) {
flutterLocalNotificationsPlugin.show(Random().nextInt(100000000),
message.data['title'], message.data['body'], details,
payload: message.data['url']);
}
flutterLocalNotificationsPlugin.show(Random().nextInt(100000000),
message.data['title'], message.data['body'], details,
payload: message.data['url']);
}

Future<Uint8List> _getByteArrayFromUrl(String url) async {
Expand Down
12 changes: 2 additions & 10 deletions lib/utils/remoteConfigController.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "package:dio/dio.dart";
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:package_info/package_info.dart';

Expand Down Expand Up @@ -29,21 +27,15 @@ class RemoteConfigController {
ios_version == null ||
android_version == null) {
return _instance ??= RemoteConfigController._internal(
backUrl: 'https://taxi.sparcs.org/api/',
frontUrl: 'https://taxi.sparcs.org',
ios_version: '',
android_version: '');
backUrl: '', frontUrl: '', ios_version: '', android_version: '');
}
_instance = RemoteConfigController._internal(
backUrl: backUrl,
frontUrl: frontUrl,
ios_version: ios_version,
android_version: android_version);
return _instance ??= RemoteConfigController._internal(
backUrl: 'https://taxi.sparcs.org/api/',
frontUrl: 'https://taxi.sparcs.org',
ios_version: '',
android_version: '');
backUrl: '', frontUrl: '', ios_version: '', android_version: '');
}

Future<void> init() async {
Expand Down
10 changes: 6 additions & 4 deletions lib/utils/token.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import 'dart:io';

import "package:dio/dio.dart";
import 'package:taxiapp/constants/constants.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:cookie_jar/cookie_jar.dart';
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
import 'package:taxiapp/utils/fcmToken.dart';
import 'package:taxiapp/utils/remoteConfigController.dart';

class Token {
String accessToken;
String refreshToken;
static Token? _instance;
static final _storage = FlutterSecureStorage();

final Dio _dio = Dio(connectionOptions);
final Dio _dio = Dio();
final CookieJar _cookieJar = CookieJar();

Token._internal({required this.accessToken, required this.refreshToken});
Expand Down Expand Up @@ -56,6 +56,7 @@ class Token {
}

Future<String?> getSession() async {
_dio.options.baseUrl = RemoteConfigController().backUrl;
_dio.interceptors.add(CookieManager(_cookieJar));
return _dio.get("/auth/app/token/login", queryParameters: {
"accessToken": accessToken,
Expand All @@ -74,8 +75,8 @@ class Token {
return null;
}
if (response.statusCode == 200) {
List<Cookie> cookies = await _cookieJar.loadForRequest(
Uri.parse(connectionOptions.baseUrl + "auth/app/token/login"));
List<Cookie> cookies = await _cookieJar.loadForRequest(Uri.parse(
RemoteConfigController().backUrl + "auth/app/token/login"));
for (Cookie cookie in cookies) {
if (cookie.name == "connect.sid") {
return cookie.value;
Expand All @@ -90,6 +91,7 @@ class Token {
}

Future<bool> updateAccessTokenUsingRefreshToken() {
_dio.options.baseUrl = RemoteConfigController().backUrl;
return _dio.get("/auth/app/token/refresh", queryParameters: {
"accessToken": accessToken,
"refreshToken": refreshToken,
Expand Down
24 changes: 0 additions & 24 deletions lib/views/taxiView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -386,30 +386,6 @@ class TaxiView extends HookWidget {
}
}
},
onUpdateVisitedHistory:
(controller, url, androidIsReload) async {
// 로그아웃 링크 감지
if (url.toString().contains("logout") && isAuthLogin.value) {
await controller.stopLoading();
try {
await FcmToken().removeToken(Token().getAccessToken());
await Token().deleteAll();
isLogin.value = false;
isAuthLogin.value = false;
await _cookieManager.deleteAllCookies();
await _controller.value!.loadUrl(
urlRequest: URLRequest(url: Uri.parse(address)));
} catch (e) {
// TODO
Fluttertoast.showToast(
msg: "서버와의 연결에 실패했습니다.",
toastLength: Toast.LENGTH_SHORT,
textColor: toastTextColor,
backgroundColor: toastBackgroundColor);
isAuthLogin.value = false;
}
}
},
onLoadResourceCustomScheme: (controller, url) async {
if (Platform.isAndroid) {
if (url.scheme == 'intent') {
Expand Down

0 comments on commit 77741da

Please sign in to comment.