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

Update example app and README to recommend initializing Firebase prior to NFA #702

Merged
merged 6 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ Make sure peer dependencies are also installed:

`yarn add firebase firebase-admin next react react-dom`

> ⚠️ Note: we recommend pinning `firebase` to 9.16.0 until issue [#614](https://github.com/gladly-team/next-firebase-auth/issues/614) is resolved

Create a module to initialize `next-firebase-auth`.

#### Example config:
Expand All @@ -77,9 +75,17 @@ _See [config documentation](#config) for details_

```js
// ./initAuth.js
import { initializeApp } from 'firebase/app'
import { init } from 'next-firebase-auth'

const initAuth = () => {
const firebaseClientInitConfig = {
apiKey: 'MyExampleAppAPIKey123', // required
authDomain: 'my-example-app.firebaseapp.com',
databaseURL: 'https://my-example-app.firebaseio.com',
projectId: 'my-example-app-id',
}
initializeApp(firebaseClientInitConfig)
init({
authPageURL: '/auth',
appPageURL: '/',
Expand All @@ -103,12 +109,7 @@ const initAuth = () => {
},
// Use application default credentials (takes precedence over firebaseAdminInitConfig if set)
// useFirebaseAdminDefaultCredential: true,
firebaseClientInitConfig: {
apiKey: 'MyExampleAppAPIKey123', // required
authDomain: 'my-example-app.firebaseapp.com',
databaseURL: 'https://my-example-app.firebaseio.com',
projectId: 'my-example-app-id',
},
firebaseClientInitConfig,
// tenantId: 'example-tenant-id', // Optional, only necessary in multi-tenant configuration
cookies: {
name: 'ExampleApp', // required
Expand Down Expand Up @@ -238,7 +239,9 @@ export default withUser()(Demo)

#### `init(config)`

Initializes `next-firebase-auth`, taking a [config](#config) object. **Must be called** before calling any other method.
Initializes `next-firebase-auth`, taking a [config](#config) object.
* This **must** before calling any other method.
* We recommend initializing the Firebase client SDK prior to calling this.

#### `withUser({ ...options })(PageComponent)`

Expand Down Expand Up @@ -523,7 +526,7 @@ When true, `firebase-admin` will implicitly find your hosting environment servic

`Object`

Configuration passed to the Firebase JS SDK's [`initializeApp`](https://firebase.google.com/docs/reference/node/firebase#initializeapp). The `firebaseClientInitConfig.apiKey` value is **always required**. Other properties are required unless you initialize the `firebase` app yourself before initializing `next-firebase-auth` (or, less commonly, if you're running `next-firebase-auth` solely on the server side).
Configuration matching Firebase JS SDK's [`initializeApp`](https://firebase.google.com/docs/reference/node/firebase#initializeapp). The `firebaseClientInitConfig.apiKey` value is **always required**. We recommend initializing the Firebase client SDK yourself prior to initializing `next-firebase-auth`; however, `next-firebase-auth` will attempt to initialize Firebase if a Firebase app does not already exist.

#### cookies

Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"deploy": "vercel --prod"
},
"dependencies": {
"firebase": "9.16.0",
"firebase": "9.17.1",
"firebase-admin": "^11.9.0",
"next": "13.4.9",
"next-absolute-url": "^1.2.2",
Expand Down
18 changes: 12 additions & 6 deletions example/utils/initAuth.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
/* globals window */
import { initializeApp } from 'firebase/app'
import { init } from 'next-firebase-auth'
import absoluteUrl from 'next-absolute-url'

const TWELVE_DAYS_IN_MS = 12 * 60 * 60 * 24 * 1000

const initAuth = () => {
// Initialize Firebase.
const firebaseClientInitConfig = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.NEXT_PUBLIC_FIREBASE_DATABASE_URL,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
}
initializeApp(firebaseClientInitConfig)

// Initialize next-firebase-auth.
init({
debug: true,

Expand Down Expand Up @@ -78,12 +89,7 @@ const initAuth = () => {
},
databaseURL: process.env.NEXT_PUBLIC_FIREBASE_DATABASE_URL,
},
firebaseClientInitConfig: {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.NEXT_PUBLIC_FIREBASE_DATABASE_URL,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
},
firebaseClientInitConfig,
cookies: {
name: 'ExampleApp',
keys: [
Expand Down
Loading
Loading