Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save heytulsiprasad/d4cea7e321c8a49c8982d387351da304 to your computer and use it in GitHub Desktop.
Send the idToken after authentication to server to generate customToken
// 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) => {
// Do stuff
})
.catch((error) => console.error(error));
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment