Files
tripz/lib/controller/auth/apple_signin_controller.dart
Hamza-Ayed 929ecf39f9 6/27/1
2024-06-27 17:41:40 +03:00

47 lines
1.3 KiB
Dart

import 'package:firebase_auth/firebase_auth.dart';
import 'package:get/get.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
class AuthController extends GetxController {
final FirebaseAuth _auth = FirebaseAuth.instance;
Future<User?> signInWithApple() async {
try {
print('Starting Apple Sign In process');
final appleCredential = await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName,
],
);
print('Apple ID Credential obtained');
final oAuthProvider = OAuthProvider('apple.com');
final credential = oAuthProvider.credential(
idToken: appleCredential.identityToken,
accessToken: appleCredential.authorizationCode,
);
print('OAuth credential created');
UserCredential userCredential =
await _auth.signInWithCredential(credential);
print('User signed in successfully: ${userCredential.user?.uid}');
return userCredential.user;
} catch (error) {
print('Error during Apple Sign In: $error');
return null;
}
}
Future<void> signOut() async {
try {
await _auth.signOut();
print('User signed out successfully');
} catch (error) {
print('Error during sign out: $error');
}
}
}