Skip to content

Commit 6445eb6

Browse files
authored
feat(adapters): move to firebase-admin in Firebase Adapter (#6225)
Co-authored-by: Balázs Orbán <[email protected]> fixes #5049 closes #6230 closes #5449 closes #5055 fixes #4927 BREAKING CHANGE: The adapter now expects `firebase-admin` instead of the `firebase` package and also supports either passing a config object or a firestore instance.
1 parent e9d8805 commit 6445eb6

File tree

22 files changed

+1825
-1788
lines changed

22 files changed

+1825
-1788
lines changed

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ npm-debug.log*
1212
yarn-debug.log*
1313
yarn-error.log*
1414
firebase-debug.log
15+
ui-debug.log
1516
.pnpm-debug.log
1617

1718

@@ -78,9 +79,6 @@ docs/.docusaurus
7879
docs/providers.json
7980

8081
# Core
81-
packages/core/*.js
82-
packages/core/*.d.ts
83-
packages/core/*.d.ts.map
8482
packages/core/src/providers/oauth-types.ts
8583
packages/core/lib
8684
packages/core/providers
@@ -96,3 +94,7 @@ packages/frameworks-sveltekit/.svelte-kit
9694
packages/frameworks-sveltekit/package
9795
packages/frameworks-sveltekit/vite.config.js.timestamp-*
9896
packages/frameworks-sveltekit/vite.config.ts.timestamp-*
97+
98+
# Adapters
99+
100+
docs/docs/reference/adapter

docs/docs/guides/03-basics/refresh-token-rotation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Using a JWT to store the `refresh_token` is less secure than saving it in a data
2222

2323
#### JWT strategy
2424

25-
Using the [jwt](../../reference/core/interfaces/types.CallbacksOptions.md#jwt) and [session](../../reference/core/interfaces/types.CallbacksOptions.md#session) callbacks, we can persist OAuth tokens and refresh them when they expire.
25+
Using the [jwt](../../reference/core/types#jwt) and [session](../../reference/core/types#session) callbacks, we can persist OAuth tokens and refresh them when they expire.
2626

2727
Below is a sample implementation using Google's Identity Provider. Please note that the OAuth 2.0 request in the `refreshAccessToken()` function will vary between different providers, but the core logic should remain similar.
2828

docs/docs/reference/06-adapters/firebase.md

Lines changed: 0 additions & 75 deletions
This file was deleted.

docs/docusaurus.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,21 @@ const docusaurusConfig = {
226226
},
227227
},
228228
],
229+
[
230+
"docusaurus-plugin-typedoc",
231+
{
232+
...typedocConfig,
233+
id: "firebase-adapter",
234+
plugin: [require.resolve("./typedoc-mdn-links")],
235+
watch: process.env.TYPEDOC_WATCH,
236+
entryPoints: ["../packages/adapter-firebase/src/index.ts"],
237+
tsconfig: "../packages/adapter-firebase/tsconfig.json",
238+
out: "reference/adapter/firebase",
239+
sidebar: {
240+
indexLabel: "Firebase",
241+
},
242+
},
243+
],
229244
],
230245
}
231246

docs/sidebars.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,8 @@ module.exports = {
5050
label: "Database Adapters",
5151
link: { type: "doc", id: "reference/adapters/overview" },
5252
items: [
53-
{
54-
type: "autogenerated",
55-
dirName: "reference/06-adapters",
56-
// See: https://github.com/facebook/docusaurus/issues/5689
57-
// exclude: ["index"],
58-
},
53+
{ type: "doc", id: "reference/adapter/firebase/index" },
54+
{ type: "autogenerated", dirName: "reference/06-adapters" },
5955
],
6056
},
6157
{

packages/adapter-firebase/.firebaserc

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/adapter-firebase/CHANGELOG.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/adapter-firebase/README.md

Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center">
22
<br/>
33
<a href="https://authjs.dev" target="_blank">
4-
<img height="64px" src="https://authjs.dev/img/logo/logo-sm.png" /></a><img height="64px" src="https://raw.githubusercontent.com/nextauthjs/adapters/main/packages/firebase/logo.svg" />
5-
<h3 align="center"><b>Firebase Adapter</b> - NextAuth.js</h3>
4+
<img height="64px" src="https://authjs.dev/img/logo/logo-sm.png" /></a><img height="64px" src="https://raw.githubusercontent.com/nextauthjs/next-auth/main/packages/adapter-firebase/logo.svg" />
5+
<h3 align="center"><b>Firebase Adapter</b> - Auth.js</h3>
66
<p align="center">
77
Open Source. Full Stack. Own Your Data.
88
</p>
@@ -13,72 +13,12 @@
1313
</p>
1414
</p>
1515

16-
## Overview
1716

18-
This is the Firebase Adapter for [`auth.js`](https://authjs.dev). This package can only be used in conjunction with the primary `next-auth` package. It is not a standalone package.
17+
This is the official Firebase Adapter for [Auth.js](https://authjs.dev) / [NextAuth.js](https://next-auth.js.org/), using the [Firebase Admin SDK](https://firebase.google.com/docs/admin/setup) and [Firestore](https://firebase.google.com/docs/firestore).
1918

20-
You can find more Firebase information in the docs at [authjs.dev/reference/adapters/firebase](https://authjs.dev/reference/adapters/firebase).
19+
## Documentation
2120

22-
## Getting Started
23-
24-
1. Install `next-auth` and `@next-auth/firebase-adapter`.
25-
26-
```js
27-
npm install next-auth @next-auth/firebase-adapter
28-
```
29-
30-
2. Add this adapter to your `pages/api/[...nextauth].js` next-auth configuration object.
31-
32-
```js
33-
import NextAuth from "next-auth"
34-
import Providers from "next-auth/providers"
35-
import { FirestoreAdapter } from "@next-auth/firebase-adapter"
36-
37-
import { initializeApp } from "firebase/app";
38-
import { getFirestore } from "firebase/firestore"
39-
40-
const app = initializeApp({ projectId: "next-auth-test" });
41-
const firestore = getFirestore(app);
42-
43-
// For more information on each option (and a full list of options) go to
44-
// https://authjs.dev/reference/configuration/auth-options
45-
export default NextAuth({
46-
// https://authjs.dev/reference/providers/oauth-builtin
47-
providers: [
48-
Providers.Google({
49-
clientId: process.env.GOOGLE_ID,
50-
clientSecret: process.env.GOOGLE_SECRET,
51-
}),
52-
],
53-
adapter: FirestoreAdapter(firestore),
54-
...
55-
})
56-
```
57-
58-
## Options
59-
60-
When initializing the firestore adapter, you must pass in the firebase config object with the details from your project. More details on how to obtain that config object can be found [here](https://support.google.com/firebase/answer/7015592).
61-
62-
An example firebase config looks like this:
63-
64-
```js
65-
const firebaseConfig = {
66-
apiKey: "AIzaSyDOCAbC123dEf456GhI789jKl01-MnO",
67-
authDomain: "myapp-project-123.firebaseapp.com",
68-
databaseURL: "https://myapp-project-123.firebaseio.com",
69-
projectId: "myapp-project-123",
70-
storageBucket: "myapp-project-123.appspot.com",
71-
messagingSenderId: "65211879809",
72-
appId: "1:65211879909:web:3ae38ef1cdcb2e01fe5f0c",
73-
measurementId: "G-8GSGZQ44ST",
74-
}
75-
```
76-
77-
See [firebase.google.com/docs/web/setup](https://firebase.google.com/docs/web/setup) for more details.
78-
79-
> **From Firebase - Caution**: We do not recommend manually modifying an app's Firebase config file or object. If you initialize an app with invalid or missing values for any of these required "Firebase options", then your end users may experience serious issues.
80-
>
81-
> For open source projects, we generally do not recommend including the app's Firebase config file or object in source control because, in most cases, your users should create their own Firebase projects and point their apps to their own Firebase resources (via their own Firebase config file or object).
21+
Check out the [documentation](https://authjs.dev/reference/adapter/firebase) to learn how to use this adapter in your project.
8222

8323
## Contributing
8424

packages/adapter-firebase/firebase.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2-
"emulators": {
2+
"firestore": {
3+
"rules": "firestore.rules"
4+
},
5+
"emulator": {
36
"firestore": {
47
"port": 8080
58
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
rules_version = '2';
2+
3+
// Deny read/write access to all users under any conditions
4+
service cloud.firestore {
5+
match /databases/{database}/documents {
6+
match /{document=**} {
7+
allow read, write: if false;
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)