Social login in web extensions #5787
-
I'm building a chrome extension with Supabase and was wondering how to login using Google in a chrome extension. For context, I have a working Next.js app using Supabase in API routes. I can log in using email/password but not Google. Attempt 1 - copy code from Next appWhen I call Attempt 2 - Chrome App credentialsReading more into it, it looks like I need another set of credentials, so I created new ones but for a 'Chrome app' instead of a web app in the Google developer console. I added those credentials to This was based on a Firebase article. My question now is, how do I log in with Supabase using the access token I have? I've tried using Guessing this may not work since they're different google oauth clients. Maybe Any direction would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 20 replies
-
@connorlindsey yes, you need to use Basically, you need to create an extension redirect uri (by calling the Here's a sample login function for reference. You can obviously make a React hook by wrapping this inside a useEffect and adding some loading, error states and whatnot. Hope this helps you guys out! ✌️ |
Beta Was this translation helpful? Give feedback.
-
Another possible approach is popup with your website login interface, and then communicating the access token to the extension with |
Beta Was this translation helpful? Give feedback.
-
Thank you @der-ofenmeister and @connorlindsey - found this question & answer very helpful 🙏 Wanted to add that we (& our users) were frustrated with having the auth flow open in a popup, rather than in another tab where you can select between currently-signed-in accounts in 1 click instead of entering email and password in full. Have solved this so wanted to share here in case it might be useful to others. Below is a version of @der-ofenmeister's code that also takes from this SO answer. This requires the Hope it's useful 😄
|
Beta Was this translation helpful? Give feedback.
-
For anyone struggling with this, this write up worked for me: |
Beta Was this translation helpful? Give feedback.
@connorlindsey yes, you need to use
chrome.identity.launchWebAuthFlow
Basically, you need to create an extension redirect uri (by calling the
chrome.identity.getRedirectURL()
) method and add that to your supabase auth settings list of urls.That fetches you a bunch of stuff including
access_token
,refresh_token
, etc. Use therefresh_token
and invokesupabase.auth.signIn()
with that.Here's a sample login function for reference.
You can obviously make a React hook by wrapping this inside a useEffect and adding some loading, error states and whatnot.
Hope this helps you guys out! ✌️