iOS PWA and IT Job Checklist for IT Staff view
This commit is contained in:
+39
-3
@@ -305,12 +305,48 @@ Future<void> main() async {
|
||||
// listen for auth changes to register/unregister token accordingly
|
||||
supaClient.auth.onAuthStateChange.listen((data) async {
|
||||
final event = data.event;
|
||||
|
||||
// Web: register FCM token for iOS 16.4+ PWA push support.
|
||||
// Requires the VAPID key from Firebase Console → Project Settings →
|
||||
// Cloud Messaging → Web Push certificates → Key pair.
|
||||
// Add VAPID_KEY=<your_key> to your .env file.
|
||||
if (kIsWeb) {
|
||||
debugPrint(
|
||||
'auth state change $event on web: skipping FCM token handling',
|
||||
);
|
||||
final vapidKey = dotenv.env['VAPID_KEY'] ?? '';
|
||||
if (vapidKey.isEmpty) {
|
||||
debugPrint(
|
||||
'Web FCM: VAPID_KEY not set in .env — skipping token registration.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (event == AuthChangeEvent.signedIn) {
|
||||
try {
|
||||
final token = await FirebaseMessaging.instance.getToken(
|
||||
vapidKey: vapidKey,
|
||||
);
|
||||
if (token != null) {
|
||||
final ctrl = NotificationsController(supaClient);
|
||||
await ctrl.registerFcmToken(token);
|
||||
debugPrint('Web FCM token registered');
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Web FCM token registration failed: $e');
|
||||
}
|
||||
} else if (event == AuthChangeEvent.signedOut) {
|
||||
try {
|
||||
final token = await FirebaseMessaging.instance.getToken(
|
||||
vapidKey: vapidKey,
|
||||
);
|
||||
if (token != null) {
|
||||
final ctrl = NotificationsController(supaClient);
|
||||
await ctrl.unregisterFcmToken(token);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Web FCM token unregister failed: $e');
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String? token;
|
||||
try {
|
||||
token = await FirebaseMessaging.instance.getToken();
|
||||
|
||||
Reference in New Issue
Block a user