How to set auth properly from user object gotten from the popup #8704
Unanswered
mukuljainx
asked this question in
Q&A
Replies: 1 comment
-
|
The issue here is that Firebase Auth cannot reconstruct a In a Chrome extension, the right pattern is to pass the credential (not the user object) between contexts and call // In your popup/background, after the Google sign-in succeeds:
const result = await signInWithPopup(auth, new GoogleAuthProvider());
const credential = GoogleAuthProvider.credentialFromResult(result);
// Serialize just the tokens (not the User)
chrome.storage.session.set({
accessToken: credential.accessToken,
idToken: credential.idToken
});Then in your extension (service worker or content script): import { getAuth, GoogleAuthProvider, signInWithCredential } from "firebase/auth";
const { accessToken, idToken } = await chrome.storage.session.get(["accessToken", "idToken"]);
const credential = GoogleAuthProvider.credential(idToken, accessToken);
const auth = getAuth();
await signInWithCredential(auth, credential);
// auth.currentUser is now properly setThis works because A few things to watch out for:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am following the guide https://dev.to/lvn1/google-authentication-in-a-chrome-extension-with-firebase-2bmo, to get the user tokens for my extension, current issue is I am unable to set
authcorrectly from the user object, I don't see any such function as response only contains JSON, it is not possible to use theupdateCurrentUseruser function as well.If anyone has faced the same issue, kindly guide!
Beta Was this translation helpful? Give feedback.
All reactions