class SignInWithAppleButton extends HookConsumerWidget {
const SignInWithAppleButton({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
return ElevatedButton(
onPressed: () async {
const baseUrl = AppwriteConstants.appleOAuthUrl;
final queryParams = {
'project': AppwriteConstants.projectId,
'scope': 'email name',
};
final fullUrl = Uri.parse(baseUrl).replace(queryParameters: queryParams);
await FlutterWebAuth2.authenticate(
url: fullUrl.toString(),
callbackUrlScheme: AppwriteConstants.oAuthCallbackScheme,
options: const FlutterWebAuth2Options(preferEphemeral: true),
).then((value) async {
final url = Uri.parse(value);
final secret = url.queryParameters['secret'];
if (secret == null) throw Exception('Invalid response from Apple');
await ref.read(localCacheHandlerProvider).setSession(secret);
}).onError((error, stackTrace) {});
},
child: const Text('Sign in With Apple'),
);
}
}
//oAuthCallbackScheme = 'appwrite-callback-<PROJECT_ID>';
//appleOAuthUrl = '<API_ENDPOINT>/account/sessions/oauth2/apple';
// Google Sign In similar as Apple