5/27/1
This commit is contained in:
35
lib/controller/auth/apple_signin_controller.dart
Normal file
35
lib/controller/auth/apple_signin_controller.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
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 {
|
||||
final appleCredential = await SignInWithApple.getAppleIDCredential(
|
||||
scopes: [
|
||||
AppleIDAuthorizationScopes.email,
|
||||
AppleIDAuthorizationScopes.fullName,
|
||||
],
|
||||
);
|
||||
|
||||
final oAuthProvider = OAuthProvider('apple.com');
|
||||
final credential = oAuthProvider.credential(
|
||||
idToken: appleCredential.identityToken,
|
||||
accessToken: appleCredential.authorizationCode,
|
||||
);
|
||||
|
||||
UserCredential userCredential =
|
||||
await _auth.signInWithCredential(credential);
|
||||
return userCredential.user;
|
||||
} catch (error) {
|
||||
print("Error during Apple sign-in: $error");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void signOut() async {
|
||||
await _auth.signOut();
|
||||
}
|
||||
}
|
||||
@@ -66,8 +66,9 @@ class LoginController extends GetxController {
|
||||
if (jsonDecoeded['status'] == 'success' &&
|
||||
jsonDecoeded['data'][0]['verified'] == 1) {
|
||||
//
|
||||
box.write(BoxName.isVerified, 'true');
|
||||
box.write(BoxName.isVerified, '1');
|
||||
box.write(BoxName.email, jsonDecoeded['data'][0]['email']);
|
||||
box.write(BoxName.phone, jsonDecoeded['data'][0]['phone']);
|
||||
|
||||
print(box.read(BoxName.tokenFCM));
|
||||
var token = await CRUD().get(link: AppLink.getTokens, payload: {
|
||||
@@ -78,12 +79,14 @@ class LoginController extends GetxController {
|
||||
if (token != 'failure') {
|
||||
if (jsonDecode(token)['data'][0]['token'] !=
|
||||
box.read(BoxName.tokenFCM)) {
|
||||
print('token changed');
|
||||
Get.put(FirebaseMessagesController())
|
||||
.sendNotificationToAnyWithoutData(
|
||||
'token change',
|
||||
'change device',
|
||||
jsonDecode(token)['data'][0]['token'].toString(),
|
||||
);
|
||||
Future.delayed(const Duration(seconds: 1));
|
||||
await CRUD().post(link: AppLink.addTokens, payload: {
|
||||
'token': box.read(BoxName.tokenFCM),
|
||||
'passengerID': box.read(BoxName.passengerID).toString()
|
||||
|
||||
@@ -116,7 +116,7 @@ class RegisterController extends GetxController {
|
||||
payload: payload,
|
||||
);
|
||||
if (jsonDecode(res1)['status'] == 'success') {
|
||||
box.write(BoxName.isVerified, 'true');
|
||||
box.write(BoxName.isVerified, '1');
|
||||
box.write(BoxName.phone, '+2${phoneController.text}');
|
||||
Get.offAll(const MapPagePassenger());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user