Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/sparcs-kaist/taxi-app into #72
Browse files Browse the repository at this point in the history
-bug-taxi-request-origin-header
  • Loading branch information
ybmin committed Sep 8, 2023
2 parents 49b429a + 0a0871b commit 54af1e8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 64 deletions.
11 changes: 0 additions & 11 deletions lib/constants/constants.dart

This file was deleted.

6 changes: 4 additions & 2 deletions lib/utils/fcmToken.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "package:dio/dio.dart";
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:taxiapp/utils/remoteConfigController.dart';

class FcmToken {
String token;
Expand All @@ -22,8 +23,7 @@ class FcmToken {
final token = await FirebaseMessaging.instance.getToken();
_dio.interceptors
.add(InterceptorsWrapper(onRequest: (options, handler) async {
options.baseUrl =
"https://taxi.dev.sparcs.org/"; //TODO: remove hardcoding
options.baseUrl = "https://taxi.sparcs.org/"; //TODO: remove hardcoding
options.headers["Origin"] = options.uri.origin;
return handler.next(options);
}, onResponse: (response, handler) async {
Expand All @@ -42,6 +42,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 @@ -53,6 +54,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
20 changes: 6 additions & 14 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://api.taxi.dev.sparcs.org/',
frontUrl: 'https://taxi.dev.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://api.taxi.dev.sparcs.org/',
frontUrl: 'https://taxi.dev.sparcs.org/',
ios_version: '',
android_version: '');
backUrl: '', frontUrl: '', ios_version: '', android_version: '');
}

Future<void> init() async {
Expand All @@ -54,18 +46,18 @@ class RemoteConfigController {
minimumFetchInterval: Duration.zero,
));
await remoteConfig.setDefaults({
"back_url": "https://api.taxi.dev.sparcs.org/",
"front_url": "https://taxi.dev.sparcs.org/",
"back_url": "https://taxi.sparcs.org/api/",
"front_url": "https://taxi.sparcs.org/",
"version": value.version,
"ios_version": value.version,
});

await remoteConfig.fetchAndActivate();

this.backUrl =
"https://api.taxi.dev.sparcs.org/"; // remoteConfig.getString("back_url");
"https://taxi.sparcs.org/api/"; // remoteConfig.getString("back_url");
this.frontUrl =
"https://taxi.dev.sparcs.org/"; // remoteConfig.getString("front_url");
"https://taxi.sparcs.org/"; // remoteConfig.getString("front_url");
this.android_version = remoteConfig.getString("version");
this.ios_version = remoteConfig.getString("ios_version");

Expand Down
12 changes: 7 additions & 5 deletions lib/utils/token.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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;
Expand Down Expand Up @@ -33,8 +33,7 @@ class Token {
_dio.interceptors.add(CookieManager(_cookieJar));
_dio.interceptors
.add(InterceptorsWrapper(onRequest: (options, handler) async {
options.baseUrl =
"https://taxi.dev.sparcs.org/"; //TODO: remove hardcoding
options.baseUrl = "https://taxi.sparcs.org/"; //TODO: remove hardcoding
options.headers["Origin"] = options.uri.origin;
return handler.next(options);
}, onResponse: (response, handler) async {
Expand Down Expand Up @@ -68,6 +67,8 @@ 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,
"deviceToken": FcmToken().fcmToken
Expand All @@ -85,8 +86,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 @@ -101,6 +102,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
28 changes: 1 addition & 27 deletions lib/views/taxiView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,30 +407,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: Colors.black,
backgroundColor: Colors.white);
isAuthLogin.value = false;
}
}
},
onLoadResourceCustomScheme: (controller, url) async {
if (Platform.isAndroid) {
if (url.scheme == 'intent') {
Expand Down Expand Up @@ -461,9 +437,7 @@ class TaxiView extends HookWidget {
// 될 때까지 리로드
if (!isLoaded.value && LoadCount.value < 10) {
LoadCount.value++;
}

if (code == -2) {
} else if (isServerError.value == false) {
Fluttertoast.showToast(
msg: "서버와의 연결에 실패했습니다.",
toastLength: Toast.LENGTH_SHORT,
Expand Down

0 comments on commit 54af1e8

Please sign in to comment.