Skip to content

Instantly share code, notes, and snippets.

@heytulsiprasad
Created June 11, 2021 16:29
Show Gist options
  • Select an option

  • Save heytulsiprasad/fc5525aa7432c8450b7a854bf24b7412 to your computer and use it in GitHub Desktop.

Select an option

Save heytulsiprasad/fc5525aa7432c8450b7a854bf24b7412 to your computer and use it in GitHub Desktop.
Redirect user to route passing custom token as URL param
// Web: React
import { auth } from "./config/firebase";
auth.onAuthStateChanged((user) => {
if (user) {
user.getIdToken(true).then((idToken) => {
// This is where to call the API
const requestOptions = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ idToken }),
};
fetch(
`https://native-redirect-firebase-admin.herokuapp.com/verify-token`,
requestOptions
)
.then((response) => response.json())
.then((data) => {
// Pass customToken as URL Param
window.location =
window.location.origin + `/customToken=${data.customToken}`;
})
.catch((error) => console.error(error));
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment