NextJS Firebase Auth Crash Course
Why Stack Overflow recommends it
Stack Overflow users cite it as the tutorial they followed when building Next.js and Firebase auth, then link it while asking about errors that come up in that setup.
Recommended by 0 people across 0 different months, 2021 to 2022.
What it is
A 46-minute coding tutorial by James Perkins that walks through adding Firebase Authentication to a Next.js app. It covers setting up the Firebase client and admin SDKs, building an AuthContext provider, a login page, and a server-side authenticated route.
What people said
Cites artooras · 2021-07 · Stack Overflow · on “Error: Firebase ID token has no "kid" claim”
Firebase documentation states that custom claims can be accessed like so [LINK] : admin .auth() .verifyIdToken(idToken) .then((claims) => { if (claims.admin === true) { // Allow access to requested admin resource. } }); I have implemented Firebase auth following this sample project [LINK] and tutorial [this video] . Specifically, the token is being decoded inside Next.JS' getServerSideProps here [LINK] . It's also worth mentioning that I'm running this project in development mode with Firebase Emulators. So, on calling: verifyIdToken(token) I get this error message: Error: Firebase ID token has no "kid" claim. See [LINK] for details on how to retrieve an ID token. Any idea where I'm failing? ----
Cites justTil · 2022-01 · Stack Overflow · on “Next.js & Firebase -> TypeError: Cannot read properties of undefined (reading 'apps')”
what I am trying to do, is to code an auth. with NextJS and Firebase. Now the problem appears in my firebaseClient.js, where I get the error "TypeError: Cannot read properties of undefined (reading 'apps')". The code looks like this: import firebase from "firebase/app"; import "firebase/auth"; import "firebase/database"; const FIREBASE_CONFIG = { // config files from firebase here }; export default function firebaseClient() { if (!firebase.apps.length) { firebase.initializeApp(FIREBASE_CONFIG); } } In the console I get this error: Terminal Error [LINK] This appears on the localhost:3000: Error Page on localhost:3000 [LINK] I am following this YT tutorial here [this video] , which is from 2020, so
Cites mukunda · 2022-01 · Stack Overflow · on “Firebase :: Cannot read property of 'uid' of null”
I have created a basic project in NextJS using Firebase. The user has to create an account using email and password. During the signup process, a "patient" (patient name) field, which is a string, also has to be entered which is saved in the Cloud Firestore during the sign-up process with the same uid as that of the user. I am trying to access the "patient" field from the Cloud Firestore on another page (random.js) but it is not working as expected. How do I fix it? P.S: I am wrapping the entire thing in an AuthProvider Context as mentioned in this [this video] tutorial. signUp.js: import { useState } from "react"; import firebaseClient from "../firebaseClient"; import "firebase/compat/auth"; imp
Cites me-me · 2022-02 · Stack Overflow · on “using cookies to save firebase token”
I've been following along with this [this video] but one thing comes to mind is the safety of storing a firebase token in a cookie ? Couldn't anyone just use that token and keep hitting firebase. const handleUser = async (user) => { if (!user) { nookies.set(undefined, "token", ""); return; } const token = await user.getIdToken(); setUser(user); nookies.set(undefined, "token", token); setLoading(false); }; useEffect(() => { const unsubscribe = onIdTokenChanged(getAuth(), handleUser); return () => unsubscribe(); }, []); The above code is a hook that just watches for changes on onIdTokenChanged handler and sets cookies on the front end with the token from firbase. Anyone know if this is safe and if