'Firebase cross domain authentication using only frontend
“Cross domain authentication” and “subdomain authentication” such questions are old and repeatedly asking questions in stack overflow. However all of the things are integrating using backend application but I need authenticate to two or more sub-domain or cross domain authentication using only front-end application and firebase.
If it possible by using JavaScript it helps to all front-end developer.
If it possible to do please help me or redirect me right ref
I have already tried as below
Form Main Domain http://localhost:3000 : Authenticated main domain use exist Signed In
() => {
const { getAuth, onAuthStateChanged } = require('firebase/auth')
const auth = getAuth(app);
onAuthStateChanged(auth, (UserCredential: any) => {
if (UserCredential) {
let refreshToken = UserCredential.stsTokenManager.refreshToken
console.log(refreshToken)
window.location.href = `http://localhost:3001/Auth?id=${refreshToken}`
} else { console.log("User is signed out") }
});
For Sub-Domain http://localhost:3001 : Required to Authenticated
var url_string = window.location.href
var url = new URL(url_string);
var token_From_url = url.searchParams.get("id");
const auth = getAuth(app);
signInWithCustomToken(auth, token_From_url)
.then((userCredential) => {
let j = userCredential.operationType
// Signed in
const user = userCredential.user
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
console.log("errorCode :", errorCode);
console.log("errorMessage :", errorMessage)
});
}
I got error
errorCode : auth/invalid-custom-token Auth.tsx:23 errorMessage :
Firebase: Invalid assertion format. 3 dot separated segments required. (auth/invalid-custom-token). Auth.tsx:22
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
