Skip to content

Commit

Permalink
apple sign in finished
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgunozerk committed Dec 13, 2023
1 parent 5bd0026 commit b4d22e9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
ACA7CE36BAED7CABEDBB43BB /* 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>"; };
C52496862A8FF4EC00D96AD7 /* RunnerProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = RunnerProfile.entitlements; sourceTree = "<group>"; };
C54DA381295EF6ED006897D5 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
C5D47E882B298315006F2F59 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = "<group>"; };
DFFD907D4C8B1E7250C8A39E /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
E50AB7C37D5DE20CAA73B507 /* GoogleService-Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "Runner/GoogleService-Info.plist"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -117,6 +118,7 @@
97C146F01CF9000F007C117D /* Runner */ = {
isa = PBXGroup;
children = (
C5D47E882B298315006F2F59 /* Runner.entitlements */,
C52496862A8FF4EC00D96AD7 /* RunnerProfile.entitlements */,
C54DA381295EF6ED006897D5 /* GoogleService-Info.plist */,
97C146FA1CF9000F007C117D /* Main.storyboard */,
Expand Down Expand Up @@ -502,6 +504,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 1.0.3;
DEVELOPMENT_TEAM = FMKLV2S32W;
ENABLE_BITCODE = NO;
Expand All @@ -528,6 +531,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 1.0.3;
DEVELOPMENT_TEAM = FMKLV2S32W;
ENABLE_BITCODE = NO;
Expand Down
10 changes: 10 additions & 0 deletions ios/Runner/Runner.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
</dict>
</plist>
7 changes: 6 additions & 1 deletion ios/Runner/RunnerProfile.entitlements
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
</dict>
</plist>
12 changes: 12 additions & 0 deletions lib/controllers/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ class LoginController extends GetxController {
return true;
}

Future<bool> appleLogin() async {
try {
final appleProvider = AppleAuthProvider();
_firebaseUser =
(await FirebaseAuth.instance.signInWithProvider(appleProvider)).user;
update();
return true;
} catch (_) {
return false;
}
}

Future<void> afterLogin() async {
// initialize these controllers after successful login immediately

Expand Down
20 changes: 20 additions & 0 deletions lib/presentation/pages/onboarding/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ class LoginPage extends GetView<LoginController> {
icon: const Icon(Ionicons.logo_google),
label: const Text("Sign up with Google"),
),
const Padding(padding: EdgeInsets.all(16)),
ElevatedButton.icon(
onPressed: () async {
bool loginSuccessful = await controller.appleLogin();
if (loginSuccessful) {
// Push a new page with only loading animation
loadingAnimation();
(await SharedPreferences.getInstance())
.setBool('isLoggedIn', true); // Save the login status
await controller
.afterLogin(); // `afterLogin` will transition into a new page after it's completed
}
},
style: ElevatedButton.styleFrom(
foregroundColor: howBlack,
backgroundColor: howWhite,
minimumSize: const Size(double.infinity, 50)),
icon: const Icon(Ionicons.logo_apple),
label: const Text("Sign up with Apple"),
),
],
),
),
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies:
loading_animation_widget: ^1.2.0+4
flutter_native_splash: ^2.3.5
url_launcher: ^6.2.1
sign_in_with_apple: ^5.0.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit b4d22e9

Please sign in to comment.