Skip to content

Using next-auth FirebaseAdapter with GoogleProvider together with Firebase getFirestore(app) #7157

Closed Answered by yvokeller
yvokeller asked this question in Help
Discussion options

You must be logged in to vote

I was able to solve this, leaving the solution here in case anybody comes across the same situation:

One approach to achieve this is to use a custom token generated by your Next.js server and use it to sign in the user client-side with Firebase.

Here's a high-level overview:

  1. When a user logs in via NextAuth, create a custom token using the Firebase Admin SDK in your Next.js server.
  2. Return the custom token in the NextAuth session.
  3. In your client-side code, use the custom token to sign in the user with Firebase.
  4. Now, the client-side Firebase instance should be aware of the user's authentication state, and Firestore rules should work as expected.

Implementation:

  1. Install the Firebase Admin…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@vikyw89
Comment options

@Martinnord
Comment options

@Hussain760
Comment options

@Mudit18
Comment options

Answer selected by yvokeller
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
7 participants