Created
June 11, 2021 16:29
-
-
Save heytulsiprasad/fc5525aa7432c8450b7a854bf24b7412 to your computer and use it in GitHub Desktop.
Redirect user to route passing custom token as URL param
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) => { | |
| // 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