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 1 commit
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
Prev Previous commit
Next Next commit
autogenerate docs from source
  • Loading branch information
balazsorban44 committed Jan 17, 2023
commit 900c51cb65461adf9fc757827c334a74e345985a
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/3_bug_adapter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ body:
- "@next-auth/dynamodb-adapter"
- "@next-auth/fauna-adapter"
- "@next-auth/firebase-adapter"
- "@next-auth/firebase-admin-adapter"
- "@next-auth/mikro-orm-adapter"
- "@next-auth/mongodb-adapter"
- "@next-auth/neo4j-adapter"
Expand Down
3 changes: 0 additions & 3 deletions .github/issue-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ fauna:
firebase:
- "@next-auth/firebase-adapter"

firebase-admin:
- "@next-auth/firebase-admin-adapter"

mikro-orm:
- "@next-auth/mikro-orm-adapter"

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,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
57 changes: 0 additions & 57 deletions docs/docs/reference/06-adapters/firebase-admin.md

This file was deleted.

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

This file was deleted.

36 changes: 20 additions & 16 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@ const docusaurusConfig = {
lastVersion: "current",
showLastUpdateAuthor: true,
showLastUpdateTime: true,
remarkPlugins: [
require("@sapphire/docusaurus-plugin-npm2yarn2pnpm").npm2yarn2pnpm,
require("remark-github"),
],
remarkPlugins: [require("@sapphire/docusaurus-plugin-npm2yarn2pnpm").npm2yarn2pnpm, require("remark-github")],
versions: {
current: {
label: "experimental",
Expand All @@ -205,15 +202,7 @@ const docusaurusConfig = {
...typedocConfig,
id: "core",
plugin: ["./tyepdoc"],
entryPoints: [
"index.ts",
"adapters.ts",
"errors.ts",
"jwt.ts",
"types.ts",
]
.map((e) => `${coreSrc}/${e}`)
.concat(providers),
entryPoints: ["index.ts", "adapters.ts", "errors.ts", "jwt.ts", "types.ts"].map((e) => `${coreSrc}/${e}`).concat(providers),
tsconfig: "../packages/core/tsconfig.json",
out: "reference/03-core",
watch: process.env.TYPEDOC_WATCH,
Expand All @@ -226,15 +215,30 @@ const docusaurusConfig = {
...typedocConfig,
id: "sveltekit",
plugin: ["./tyepdoc"],
entryPoints: ["index.ts", "client.ts"].map(
(e) => `../packages/frameworks-sveltekit/src/lib/${e}`
),
entryPoints: ["index.ts", "client.ts"].map((e) => `../packages/frameworks-sveltekit/src/lib/${e}`),
tsconfig: "../packages/frameworks-sveltekit/tsconfig.json",
out: "reference/04-sveltekit",
watch: process.env.TYPEDOC_WATCH,
includeExtension: false,
},
],
[
"docusaurus-plugin-typedoc",
{
...typedocConfig,
id: "firebase-adapter",
plugin: ["./tyepdoc"],
entryPoints: ["../packages/adapter-firebase/src/index.ts"],
tsconfig: "../packages/adapter-firebase/tsconfig.json",
out: "reference/adapter/firebase",
watch: process.env.TYPEDOC_WATCH,
includeExtension: false,
sidebar: {
position: 1,
indexLabel: "Firebase",
},
},
],
],
}

Expand Down
4 changes: 4 additions & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ module.exports = {
label: "Database Adapters",
link: { type: "doc", id: "reference/adapters/overview" },
items: [
{
type: "doc",
id: "reference/adapter/firebase/index",
},
{
type: "autogenerated",
dirName: "reference/06-adapters",
Expand Down
10 changes: 7 additions & 3 deletions docs/typedoc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"excludeNotDocumented": true,
"$schema": "https://typedoc.org/schema.json",
"allReflectionsHaveOwnDocument": true,
"disableSources": true,
"hideBreadcrumbs": true,
"excludeExternals": true,
Expand All @@ -17,7 +16,12 @@
"JsonValue"
],
"readme": "none",
"sort": ["kind", "static-first", "required-first", "alphabetical"],
"sort": [
"kind",
"static-first",
"required-first",
"alphabetical"
],
"kindSortOrder": [
"Function",
"TypeAlias",
Expand All @@ -42,4 +46,4 @@
"GetSignature",
"SetSignature"
]
}
}
2 changes: 1 addition & 1 deletion packages/adapter-firebase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

## Overview

This is the Firebase Admin 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 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.

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

Expand Down
56 changes: 56 additions & 0 deletions packages/adapter-firebase/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
*
* @module @next-auth/firebase-adapter
*/

import { firestore } from "firebase-admin"

import type {
Expand Down Expand Up @@ -133,6 +138,57 @@ export interface FirestoreAdapterOptions {
preferSnakeCase?: boolean
}

/**
*
* 1. Install the necessary packages
*
* ```bash npm2yarn2pnpm
* npm install next-auth @next-auth/firebase-admin-adapter firebase-admin
* ```
*
* 2. Create a Firebase project and generate a service account key. See [instructions](https://firebase.google.com/docs/admin/setup).
*
* 3. Add this adapter to your `pages/api/auth/[...nextauth].js` next-auth configuration object.
*
* ```ts title="pages/api/auth/[...nextauth].js"
* import NextAuth from "next-auth"
* import GoogleProvider from "next-auth/providers/google"
* import { FirestoreAdminAdapter } from "@next-auth/firebase-admin-adapter"
*
* import admin from "firebase-admin"
*
* // Initialize the firebase admin app. By default, the firebase admin sdk will
* // look for the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
* // that to authenticate with the firebase project. See other authentication
* // methods here: https://firebase.google.com/docs/admin/setup
* const app = admin.initializeApp()
*
* const firestore = app.firestore()
*
* // 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/
* providers: [
* GoogleProvider({
* clientId: process.env.GOOGLE_ID,
* clientSecret: process.env.GOOGLE_SECRET,
* }),
* ],
* adapter: FirestoreAdminAdapter(firestore),
* ...
* })
* ```
*
* ## Naming Conventions
*
* If mixed snake_case and camelCase field names in the database is an issue for you, you can pass the option `preferSnakeCase: true` to the adapter. This will convert all
* fields names and collection names to snake_case e.g. the collection `verificationTokens` will instead be `verification_tokens`, and fields like `emailVerified` will instead be `email_verified`.
*
* ```ts
* FirestoreAdminAdapter(firestore, { preferSnakeCase: true })
* ```
*/
export function FirestoreAdapter(options: FirestoreAdapterOptions): Adapter {
const { db, preferSnakeCase = false } = options
const C = collestionsFactory(db, preferSnakeCase)
Expand Down