Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use firebase apps in getServerSideProps: "FirebaseError: Firebase: Need to provide options, when not being deployed to hosting via source." #696

Closed
MvRemmerden opened this issue Dec 5, 2023 · 1 comment

Comments

@MvRemmerden
Copy link
Contributor

Describe the bug

I'm not sure if I'm doing something wrong here, or if this is indeed a bug, but according to https://stackoverflow.com/a/71119461 it should be possible to use the normal client SDK for getServerSideProps. However, when I try to do so and follow the instructions in https://github.com/gladly-team/next-firebase-auth/blob/v1.x/EXAMPLES.md#using-the-firebase-apps, I always get the following error:

image

Minimal code example for the index.js (I can also provide a repo for this if it helps):

import React from 'react'
import { useUser, withUser, withUserTokenSSR } from 'next-firebase-auth'
import Header from '../components/Header'
import DemoPageLinks from '../components/DemoPageLinks'
import { getApp } from 'firebase/app'
import { getFirestore, collection, onSnapshot } from 'firebase/firestore'

const styles = {
  content: {
    padding: 32,
  },
  infoTextContainer: {
    marginBottom: 32,
  },
}

const Demo = () => {
  const user = useUser()
  return (
    <div>
      <Header email={user.email} signOut={user.signOut} />
      <div style={styles.content}>
        <div style={styles.infoTextContainer}>
          <h3>Home</h3>
          <p>
            This page does not require authentication, so it won't redirect to
            the login page if you are not signed in.
          </p>
          <p>
            If you remove `getServerSideProps` from this page, it will be static
            and load the authed user only on the client side.
          </p>
        </div>
        <DemoPageLinks />
      </div>
    </div>
  )
}

export const getServerSideProps = withUserTokenSSR()(() => {
  onSnapshot(collection(getFirestore(getApp()), 'artists'), (snap) => {
    if (!snap) {
      return;
    }
    console.log(snap);
  });
})

export default withUser()(Demo)

Versions

next-firebase-auth version: 1.0.1
Firebase JS SDK (firebase): 9.16.0
Firebase admin SDK (firebase-admin): 11.19.0
Next.js: 14.0.3

@kmjennison
Copy link
Contributor

Duplicate of #614. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants