skip to Main Content

I’m building a react-native app and right now i am trying to display my user’s name using my stored JWT so it looks like this in my code :

import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'
import React, { useState } from 'react'
import firebase from '../../firebase';
import { auth } from '../../firebase'
import { signOut } from 'firebase/auth'
import { useEffect } from 'react';
import { useNavigation } from '@react-navigation/native'
import * as SecureStore from 'expo-secure-store';
import { globalStyles } from '../../styles/global'



const SearchScreen = () => {

    const [user, setUser] = useState(null);
    

    // Get the current user's ID token
    const getCurrentUser = async (key) => {
      const idToken = await SecureStore.getItemAsync(key);
      // Decode the ID token to get user information
      const decodedToken = await auth.verifyIdToken(idToken);
      console.log("here is the decoded one :",decodedToken)
      // Set the user's information to the state
      setUser(decodedToken);
    };

    getCurrentUser('jwt');

I did setup my firebase in a "firebase.js" file in my root directory :


import { getAuth } from "firebase/auth";
import firebase from 'firebase/compat';

const firebaseConfig = {
// private infos & shit you know
};


let app;
if (firebase.apps.length === 0) {
    app = firebase.initializeApp(firebaseConfig);
} else {
    app = firebase.app()
}


const auth = getAuth();

export { auth };

So here i am trying to figure why i get this error :

WARN Possible Unhandled Promise Rejection (id: 1):
TypeError: undefined is not a function

2

Answers


  1. verifyIdToken is not a method provided by the React Native library for Firebase Authentication. You can see in the API documentation it’s not listed anywhere.

    The ability to verify an ID token is reserved only for Firebase Admin backend SDKs with code that needs to validate the user invoking the code. You can read documentation about that here. Firebase Admin does not work on frontend apps.

    Login or Signup to reply.
  2. you can use Firebase REST API to validate your ID token.
    Take a look in this section of API documentation

    PS: this will only validate firebase’s ID token. If you’re using custom JWT Tokens this will not work

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search