Created
June 11, 2021 16:04
-
-
Save heytulsiprasad/d4cea7e321c8a49c8982d387351da304 to your computer and use it in GitHub Desktop.
Send the idToken after authentication to server to generate customToken
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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