Home > Software design >  Firebase creating custom token using spotify signin?
Firebase creating custom token using spotify signin?

Time:03-18

I am trying to implement a 'Log in with Spotify' feature for my react app. I am trying to follow this blog but I am not able use

firebase.auth().createCustomToken(uid)

as i get the error

.createCustomToken is not a function

I also tried using firebase-admin package but I run into

Can't resolve util in /node_modules/@google_cloud/common/build/src

This is what I have tried to do so far. I have never used firebase before. Any help would be appreciated.

 import {getAuth} from 'firebase-admin/auth';
 import { initializeApp } from 'firebase-admin/app';
 import admin from 'firebase-admin';

var serviceAccount = require('./service-account.json')
const spotifyApi = new SpotifyWebApi();
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
})
let uid= 5;

getAuth().createCustomToken(uid).then(function(customToken) {
  console.log(customToken);
});

CodePudding user response:

The blog post you're following is a few years old, and recent versions of the Firebase SDK for JavaScript have switched to a different syntax (to allow build tools to automatically exclude unused parts of the SDK from you app bundle).

What used to be:

firebase.auth().createCustomToken(uid)...

Is now accomplished with:

createCustomToken(getAuth(), uid)...

For more on this, I recommend also checking out the upgrade guide for the new v9 SDK.


Update: as Dharmaraj commented below createCustomToken is still a method on the auth object.

  • Related