Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add google sign in #43

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ key
.env
ios/fastlane/metadata
iOS/fastlane/screenshots
ios/Runner/GoogleService-Info.plist
android/app/google-services.json
11 changes: 11 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

apply plugin: 'com.google.gms.google-services'

def versionProps = new Properties()
def versionPropsFile = rootProject.file('version.properties')
if (versionPropsFile.exists()) {
Expand Down Expand Up @@ -91,4 +93,13 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:33.5.1')

// Add the dependencies for Firebase products you want to use
implementation 'com.google.firebase:firebase-analytics'

}



1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:8.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.4.2'
}
}

Expand Down
55 changes: 43 additions & 12 deletions data/lib/repositories/auth_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class AuthRepositoryImpl implements AuthRepository {
final APIEnvironmentRepository apiEnvironmentRepository;

AuthRepositoryImpl(
{required this.client,
required this.authClient,
required this.apiEnvironmentRepository});
{required this.client, required this.authClient, required this.apiEnvironmentRepository});

@override
Future<User> signup(String email, String password, String verificationCode,
Expand All @@ -40,9 +38,10 @@ class AuthRepositoryImpl implements AuthRepository {
);

if (response.statusCode == 200 || response.statusCode == 201) {
final responseData = jsonDecode(response.body);
return User(
email: email,
name: name,
email: responseData['user']['email'],
name: responseData['user']['name'],
);
} else {
throw Exception('Failed to sign up. Status code: ${response.statusCode}');
Expand Down Expand Up @@ -107,18 +106,14 @@ class AuthRepositoryImpl implements AuthRepository {
}
}

Future<String> resetPassword(
String email, String newPassword, String confirmationCode) async {
Future<String> resetPassword(String email, String newPassword, String confirmationCode) async {
final baseURL = await apiEnvironmentRepository.getBaseUrl();
final url = Uri.parse('$baseURL/auth/reset-password');
final response = await client.post(
url,
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
"email": email,
'password': newPassword,
"confirmationCode": confirmationCode
}),
body: jsonEncode(
{"email": email, 'password': newPassword, "confirmationCode": confirmationCode}),
);

if (response.statusCode == 200) {
Expand Down Expand Up @@ -167,4 +162,40 @@ class AuthRepositoryImpl implements AuthRepository {
throw mapServerErrorToDomainException(response);
}
}

Future<String> syncUser(String? displayName, String email, String? photoUrl) async {
final baseURL = await apiEnvironmentRepository.getBaseUrl();
final url = Uri.parse('$baseURL/auth/sync-user');
final response = await client.post(
url,
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
if (displayName != null) 'displayName': displayName,
'email': email,
if (photoUrl != null) 'photoUrl': photoUrl,
}),
);

final data = jsonDecode(response.body);

if (response.statusCode == 200) {
// User already exists, backend returns an access token
final accessToken = data['accessToken'];
if (accessToken != null) {
return accessToken; // Return the access token
} else {
throw Exception('Access token missing in response');
}
} else if (response.statusCode == 201) {
// New user created, backend returns a success message
final accessToken = data['accessToken'];
if (accessToken != null) {
return accessToken; // Return the access token
} else {
throw Exception('Access token missing in response');
}
} else {
throw mapServerErrorToDomainException(response);
}
}
}
1 change: 1 addition & 0 deletions domain/lib/repositories_abstract/auth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ abstract class AuthRepository {
Future<String> resetPassword(String email, String newPassword, String confirmationCode);
Future<void> sendSignupVerificationCode(String email);
Future<String> updatePassword(String newPassword);
Future<String> syncUser(String? displayName, String email, String? photoUrl);
}
7 changes: 7 additions & 0 deletions domain/lib/usecases/auth_usecase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ class AuthUseCase {
Future<String> updatePassword(String newPassword) async {
return await repository.updatePassword(newPassword);
}

Future<String> syncUser(String? displayName, String email, String? photoUrl) async {
String accessToken = await repository.syncUser(displayName, email, photoUrl);
await tokenProvider.saveToken(accessToken);
return accessToken;
}

}


Binary file added images/apple_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/google_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
platform :ios, '13.0'
platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
42 changes: 39 additions & 3 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
PODS:
- app_tracking_transparency (0.0.1):
- Flutter
- AppAuth (1.7.5):
- AppAuth/Core (= 1.7.5)
- AppAuth/ExternalUserAgent (= 1.7.5)
- AppAuth/Core (1.7.5)
- AppAuth/ExternalUserAgent (1.7.5):
- AppAuth/Core
- device_info (0.0.1):
- Flutter
- Flutter (1.0.0)
Expand All @@ -9,6 +15,24 @@ PODS:
- fluttertoast (0.0.2):
- Flutter
- Toast
- google_sign_in_ios (0.0.1):
- AppAuth (>= 1.7.4)
- Flutter
- FlutterMacOS
- GoogleSignIn (~> 7.1)
- GTMSessionFetcher (>= 3.4.0)
- GoogleSignIn (7.1.0):
- AppAuth (< 2.0, >= 1.7.3)
- GTMAppAuth (< 5.0, >= 4.1.1)
- GTMSessionFetcher/Core (~> 3.3)
- GTMAppAuth (4.1.1):
- AppAuth/Core (~> 1.7)
- GTMSessionFetcher/Core (< 4.0, >= 3.3)
- GTMSessionFetcher (3.5.0):
- GTMSessionFetcher/Full (= 3.5.0)
- GTMSessionFetcher/Core (3.5.0)
- GTMSessionFetcher/Full (3.5.0):
- GTMSessionFetcher/Core
- in_app_review (0.2.0):
- Flutter
- launch_review (0.0.1):
Expand All @@ -33,6 +57,7 @@ DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
- fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
- google_sign_in_ios (from `.symlinks/plugins/google_sign_in_ios/darwin`)
- in_app_review (from `.symlinks/plugins/in_app_review/ios`)
- launch_review (from `.symlinks/plugins/launch_review/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
Expand All @@ -43,6 +68,10 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- AppAuth
- GoogleSignIn
- GTMAppAuth
- GTMSessionFetcher
- Toast

EXTERNAL SOURCES:
Expand All @@ -56,6 +85,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/flutter_secure_storage/ios"
fluttertoast:
:path: ".symlinks/plugins/fluttertoast/ios"
google_sign_in_ios:
:path: ".symlinks/plugins/google_sign_in_ios/darwin"
in_app_review:
:path: ".symlinks/plugins/in_app_review/ios"
launch_review:
Expand All @@ -73,10 +104,15 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
app_tracking_transparency: e169b653478da7bb15a6c61209015378ca73e375
AppAuth: 501c04eda8a8d11f179dbe8637b7a91bb7e5d2fa
device_info: d7d233b645a32c40dfdc212de5cf646ca482f175
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12
fluttertoast: e9a18c7be5413da53898f660530c56f35edfba9c
fluttertoast: 723e187574b149e68e63ca4d39b837586b903cfa
google_sign_in_ios: 07375bfbf2620bc93a602c0e27160d6afc6ead38
GoogleSignIn: d4281ab6cf21542b1cfaff85c191f230b399d2db
GTMAppAuth: f69bd07d68cd3b766125f7e072c45d7340dea0de
GTMSessionFetcher: 5aea5ba6bd522a239e236100971f10cb71b96ab6
in_app_review: 318597b3a06c22bb46dc454d56828c85f444f99d
launch_review: 75d5a956ba8eaa493e9c9d4bf4c05e505e8d5ed0
package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c
Expand All @@ -86,6 +122,6 @@ SPEC CHECKSUMS:
Toast: ec33c32b8688982cecc6348adeae667c1b9938da
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe

PODFILE CHECKSUM: cc1f88378b4bfcf93a6ce00d2c587857c6008d3b
PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048

COCOAPODS: 1.15.2
COCOAPODS: 1.12.1
37 changes: 37 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
2165F7651D3A67965C93AB30 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
411B8A022CE821BD00B9B7E6 /* Secret.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Secret.xcconfig; path = /Users/luliny/Desktop/Secret.xcconfig; sourceTree = "<absolute>"; };
5F392F2D47C5629766A586E4 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -87,6 +88,7 @@
9740EEB21CF90195004384FC /* Debug.xcconfig */,
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
9740EEB31CF90195004384FC /* Generated.xcconfig */,
411B8A022CE821BD00B9B7E6 /* Secret.xcconfig */,
);
name = Flutter;
sourceTree = "<group>";
Expand Down Expand Up @@ -141,6 +143,7 @@
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
C1DCFBA1E4FE38FAE54CF764 /* [CP] Embed Pods Frameworks */,
46BB204A6CF560EF758D1870 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -175,6 +178,9 @@
Base,
);
mainGroup = 97C146E51CF9000F007C117D;
packageReferences = (
411B8A012CE43B9300B9B7E6 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
);
productRefGroup = 97C146EF1CF9000F007C117D /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -215,6 +221,23 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
};
46BB204A6CF560EF758D1870 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
showEnvVarsInLog = 0;
};
53436BA68E70F57EF53F6557 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -305,6 +328,7 @@
/* Begin XCBuildConfiguration section */
249021D3217E4FDB00AE95B9 /* Profile */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 411B8A022CE821BD00B9B7E6 /* Secret.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -382,6 +406,7 @@
};
97C147031CF9000F007C117D /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 411B8A022CE821BD00B9B7E6 /* Secret.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -437,6 +462,7 @@
};
97C147041CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 411B8A022CE821BD00B9B7E6 /* Secret.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -566,6 +592,17 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
411B8A012CE43B9300B9B7E6 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/firebase/firebase-ios-sdk.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 11.5.0;
};
};
/* End XCRemoteSwiftPackageReference section */
};
rootObject = 97C146E61CF9000F007C117D /* Project object */;
}
Loading