skip to Main Content

I am using signInWithCustomToken() after initiating it on the server.

async function signinWithToken(data, sendResponse) {
 const { token } = data;
 console.log(token);
 signInWithCustomToken(auth, token)
   .then((user) => {
    console.log(user);
    sendResponse({ success: true, user });
})
.catch((err) => {
  sendResponse({ success: false, message: err.message 
});
  
});

}

The problem is that the user object returned doesn’t include the user details like displayName, email, etc…

enter image description here

Is there something I could do about it?

2

Answers


  1. The signInWithCustomToken() method returns a Promise which resolves with a UserCredential and not a User.

    So you need to do as follows:

    async function signinWithToken(data, sendResponse) {
     const { token } = data;
     console.log(token);
     signInWithCustomToken(auth, token)
       .then((userCredential) => {
        console.log(userCredential.user);
        //..
    })
    
    Login or Signup to reply.
  2. A custom token only contains the properties/claims that you put into it. Firebase doesn’t add any information to the custom token, so if you find certain values missing, it’s because your code didn’t add them while minting the token.

    Also see the Firebase documentation on minting a custom token using the Admin SDK.

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