Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Auth in a Flutter app with WebView

I'm developing a Flutter app that uses Firebase Auth to handle authentication. However, some sections of the app use a WebView that shows content from the web version (which also uses Firebase Auth). My question is to how ensure that users that have signed in to the app are also signed in within the WebView.

like image 844
Alex Avatar asked Nov 06 '19 09:11

Alex


People also ask

Does firebase work with Flutter web?

Flutter works with existing code, is used by developers and organizations around the world, and is free and open source. In this lab, you will create a Firebase Meetup application. The application will demonstrate how to use Firebase Web authentication in a Flutter application.


1 Answers

There's nothing built into Firebase to automatically synchronize the authentication state from native code into a web view that is opened from this native code.

It should be possible to pass the ID token from the native code to the web view and use it there, but I've never tried that myself.

Some relevant links that I found:

  • How to pass Firebase Auth token to webView and register for notifications on Android (describes the same problem, but then with Android - and unfortunately without an answer)
  • Is there a way to keep the user signed in between native code and a WebView using Firebase Auth on Android? (unfortunately also without an answer)
  • Webviews and social authentication with React Native (blog post describing a workaround for this type of problem with Facebook login and react native)
  • How to do Authentication on native and pass to webView? (also with React Native, but this answer looks promising)
  • capacitor-firebase-auth npm module (plugin for Capacitor framework that propagates the token from native code to web view)

None of these are pre-built solutions for Flutter + WebView, but I hope that combined they allow you to build something yourself. If you do: please share it! :)

like image 86
Frank van Puffelen Avatar answered Oct 11 '22 19:10

Frank van Puffelen