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

feat(adapters): move to firebase-admin in Firebase Adapter #6225

Merged
merged 27 commits into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
70f0343
add firebase-admin-adapter
wyattades Dec 30, 2022
6a7bd5d
fix type typo
wyattades Dec 30, 2022
b32d4f2
assert collections are empty before test
wyattades Dec 30, 2022
4d11596
Merge branch 'main' into firebase-admin-adapter
balazsorban44 Jan 17, 2023
c3400b4
Merge branch 'main' into firebase-admin-adapter
balazsorban44 Jan 17, 2023
e4d5591
cleanup
balazsorban44 Jan 17, 2023
900c51c
autogenerate docs from source
balazsorban44 Jan 17, 2023
498acdb
Merge branch 'main' into firebase-admin-adapter
balazsorban44 Jan 19, 2023
dfc8545
docs fixes
balazsorban44 Jan 19, 2023
b9d9888
use single-page structure for modules
balazsorban44 Jan 19, 2023
22cdfba
fix links
balazsorban44 Jan 19, 2023
0f370ff
remove `remark-github`
balazsorban44 Jan 19, 2023
f96be2b
pass config instead of instance, publish as ESM
balazsorban44 Jan 19, 2023
e695212
do not override `projectId` by default
balazsorban44 Jan 19, 2023
5a77198
update readme/docs
balazsorban44 Jan 19, 2023
ff0d74c
update jest
balazsorban44 Jan 20, 2023
e289670
fix tests
balazsorban44 Jan 20, 2023
9272802
update README
balazsorban44 Jan 20, 2023
f551453
support passing an instance
balazsorban44 Jan 20, 2023
b57ae5f
add dev command
balazsorban44 Jan 20, 2023
c4f2f34
Merge branch 'main' into firebase-admin-adapter
balazsorban44 Jan 20, 2023
bd336aa
upgrade typedoc plugins
balazsorban44 Jan 30, 2023
c3c951b
upgrade typedoc plugin
balazsorban44 Jan 30, 2023
b3caf1c
change from main to index
balazsorban44 Jan 30, 2023
6309949
update typedoc plugin
balazsorban44 Jan 31, 2023
1cd5cbb
Merge branch 'main' into firebase-admin-adapter
balazsorban44 Feb 4, 2023
7bb0689
fix `files` for publishing
balazsorban44 Feb 5, 2023
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
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log
ui-debug.log
.pnpm-debug.log


Expand Down Expand Up @@ -78,9 +79,6 @@ docs/.docusaurus
docs/providers.json

# Core
packages/core/*.js
packages/core/*.d.ts
packages/core/*.d.ts.map
packages/core/src/providers/oauth-types.ts
packages/core/lib
packages/core/providers
Expand All @@ -96,3 +94,7 @@ packages/frameworks-sveltekit/.svelte-kit
packages/frameworks-sveltekit/package
packages/frameworks-sveltekit/vite.config.js.timestamp-*
packages/frameworks-sveltekit/vite.config.ts.timestamp-*

# Adapters

docs/docs/reference/adapter
2 changes: 1 addition & 1 deletion docs/docs/guides/03-basics/refresh-token-rotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Using a JWT to store the `refresh_token` is less secure than saving it in a data

#### JWT strategy

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.
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.

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.

Expand Down
75 changes: 0 additions & 75 deletions docs/docs/reference/06-adapters/firebase.md

This file was deleted.

15 changes: 15 additions & 0 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,21 @@ const docusaurusConfig = {
},
},
],
[
"docusaurus-plugin-typedoc",
{
...typedocConfig,
id: "firebase-adapter",
plugin: [require.resolve("./typedoc-mdn-links")],
watch: process.env.TYPEDOC_WATCH,
entryPoints: ["../packages/adapter-firebase/src/index.ts"],
tsconfig: "../packages/adapter-firebase/tsconfig.json",
out: "reference/adapter/firebase",
sidebar: {
indexLabel: "Firebase",
},
},
],
],
}

Expand Down
8 changes: 2 additions & 6 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ module.exports = {
label: "Database Adapters",
link: { type: "doc", id: "reference/adapters/overview" },
items: [
{
type: "autogenerated",
dirName: "reference/06-adapters",
// See: https://github.com/facebook/docusaurus/issues/5689
// exclude: ["index"],
},
{ type: "doc", id: "reference/adapter/firebase/index" },
{ type: "autogenerated", dirName: "reference/06-adapters" },
],
},
{
Expand Down
1 change: 0 additions & 1 deletion packages/adapter-firebase/.firebaserc

This file was deleted.

16 changes: 0 additions & 16 deletions packages/adapter-firebase/CHANGELOG.md

This file was deleted.

70 changes: 5 additions & 65 deletions packages/adapter-firebase/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<p align="center">
<br/>
<a href="https://authjs.dev" target="_blank">
<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" />
<h3 align="center"><b>Firebase Adapter</b> - NextAuth.js</h3>
<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" />
<h3 align="center"><b>Firebase Adapter</b> - Auth.js</h3>
<p align="center">
Open Source. Full Stack. Own Your Data.
</p>
Expand All @@ -13,72 +13,12 @@
</p>
</p>

## Overview

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.
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).

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

## Getting Started

1. Install `next-auth` and `@next-auth/firebase-adapter`.

```js
npm install next-auth @next-auth/firebase-adapter
```

2. Add this adapter to your `pages/api/[...nextauth].js` next-auth configuration object.

```js
import NextAuth from "next-auth"
import Providers from "next-auth/providers"
import { FirestoreAdapter } from "@next-auth/firebase-adapter"

import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore"

const app = initializeApp({ projectId: "next-auth-test" });
const firestore = getFirestore(app);

// For more information on each option (and a full list of options) go to
// https://authjs.dev/reference/configuration/auth-options
export default NextAuth({
// https://authjs.dev/reference/providers/oauth-builtin
providers: [
Providers.Google({
clientId: process.env.GOOGLE_ID,
clientSecret: process.env.GOOGLE_SECRET,
}),
],
adapter: FirestoreAdapter(firestore),
...
})
```

## Options

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).

An example firebase config looks like this:

```js
const firebaseConfig = {
apiKey: "AIzaSyDOCAbC123dEf456GhI789jKl01-MnO",
authDomain: "myapp-project-123.firebaseapp.com",
databaseURL: "https://myapp-project-123.firebaseio.com",
projectId: "myapp-project-123",
storageBucket: "myapp-project-123.appspot.com",
messagingSenderId: "65211879809",
appId: "1:65211879909:web:3ae38ef1cdcb2e01fe5f0c",
measurementId: "G-8GSGZQ44ST",
}
```

See [firebase.google.com/docs/web/setup](https://firebase.google.com/docs/web/setup) for more details.

> **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.
>
> 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).
Check out the [documentation](https://authjs.dev/reference/adapter/firebase) to learn how to use this adapter in your project.

## Contributing

Expand Down
5 changes: 4 additions & 1 deletion packages/adapter-firebase/firebase.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"emulators": {
"firestore": {
"rules": "firestore.rules"
},
"emulator": {
"firestore": {
"port": 8080
}
Expand Down
10 changes: 10 additions & 0 deletions packages/adapter-firebase/firestore.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rules_version = '2';

// Deny read/write access to all users under any conditions
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
1 change: 0 additions & 1 deletion packages/adapter-firebase/jest.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/adapter-firebase/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 17 additions & 8 deletions packages/adapter-firebase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,44 @@
"Nico Domino <yo@ndo.dev>",
"Alex Meuer <github@alexmeuer.com>"
],
"main": "dist/index.js",
"type": "module",
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
}
},
"files": [
"dist",
"index.d.ts"
"src",
"*.js",
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved
"*.d.ts*"
],
"license": "ISC",
"keywords": [
"next-auth",
"next.js",
"firebase"
"firebase",
"firebase-admin"
],
"private": false,
"publishConfig": {
"access": "public"
},
"scripts": {
"dev": "tsc -w",
"build": "tsc",
"test": "FIRESTORE_EMULATOR_HOST=localhost:8080 firebase --token '$FIREBASE_TOKEN' emulators:exec --only firestore --project next-auth-test jest"
"test": "firebase emulators:exec --only firestore --project next-auth-test 'jest -c tests/jest.config.js'"
},
"peerDependencies": {
"firebase": "^9.7.0",
"firebase-admin": "^11.4.1",
"next-auth": "^4"
},
"devDependencies": {
"@next-auth/adapter-test": "workspace:*",
"@next-auth/tsconfig": "workspace:*",
"firebase": "^9.14.0",
"firebase-admin": "^11.4.1",
"firebase-tools": "^11.16.1",
"jest": "^27.4.3",
"jest": "^29.3.1",
"next-auth": "workspace:*"
}
}
58 changes: 0 additions & 58 deletions packages/adapter-firebase/src/converter.ts

This file was deleted.

Loading