Compare commits

..

10 Commits

Author SHA1 Message Date
GitHub Actions
43deda5bfb chore(release): bump package version(s) [skip ci] 2023-06-13 12:49:24 +00:00
Balázs Orbán
7e79d8c509 feat: introduce @auth/upstash-redis-adapter (#7791)
Database adapters are not dependent on Next.js features, so it makes sense to republish them under the `@auth/*` scope.

This PR is part of a series to convert adapters, using `@auth/core` for types.

BREAKING CHANGE:
If you are coming from the previous adapter, change your `package.json`:

```diff
-  "@next-auth/upstash-redis-adapter": "0.0.0",
+  "@auth/upstash-redis-adapter": "0.0.0",
```

And run `npm install`, `yarn install` or `pnpm install` respectively.

**Note:** This packages is published as ESM-only

This package assumes that `globalThis.crypto` is available.

In older Node.js versions, you can polyfill by adding:

`globalThis.crypto ??= require("node:crypto").webcrypto`
2023-06-13 14:36:38 +02:00
Balázs Orbán
ab051162a7 chore: reset @auth/mongodb-adapter version 2023-06-13 13:02:19 +01:00
Balázs Orbán
87298a0150 feat: introduce @auth/mongodb-adapter (#7790)
Database adapters are not dependent on Next.js features, so it makes sense to republish them under the `@auth/*` scope.

This PR is part of a series to convert adapters, using `@auth/core` for types.

BREAKING CHANGE:
If you are coming from the previous adapter, change your `package.json`:

```diff
-  "@next-auth/mongodb-adapter": "0.0.0",
+  "@auth/mongodb-adapter": "0.0.0",
```

And run `npm install`, `yarn install` or `pnpm install` respectively.

**Note:** This packages is published as ESM-only
2023-06-13 13:41:12 +02:00
GitHub Actions
d6abccd9a0 chore(release): bump package version(s) [skip ci] 2023-06-13 11:37:54 +00:00
Josua Frank
2f35daae37 fix(client): respect { redirect: true } in signIn() (#7775)
* Fix `signIn()` not respecting `{ redirect: true }`

* Apply suggestions from code review

---------

Co-authored-by: Balázs Orbán <info@balazsorban.com>
2023-06-13 12:14:49 +01:00
Koen Bolhuis
a0f3b04c43 docs: Fix typo in email tutorial (#7769) 2023-06-13 12:11:04 +01:00
GitHub Actions
c7dec376a1 chore(release): bump package version(s) [skip ci] 2023-06-05 21:41:46 +00:00
Gage Keenan
925a52e0ec fix: sort chunked session cookies (#7736)
Update cookie.ts
2023-06-05 17:36:10 +01:00
Imamuzzaki Abu Salam
2318e44de4 docs(cypress): update file config to latest cypress c… (#7733)
docs(testing-with-cypress.md): update file config to latest cypress config filename
2023-06-05 17:33:37 +01:00
20 changed files with 167 additions and 88 deletions

View File

@@ -26,14 +26,14 @@ body:
- "@next-auth/fauna-adapter"
- "@next-auth/firebase-adapter"
- "@next-auth/mikro-orm-adapter"
- "@next-auth/mongodb-adapter"
- "@auth/mongodb-adapter"
- "@next-auth/neo4j-adapter"
- "@next-auth/pouchdb-adapter"
- "@auth/prisma-adapter"
- "@next-auth/sequelize-adapter"
- "@next-auth/supabase-adapter"
- "@auth/typeorm-adapter"
- "@next-auth/upstash-redis-adapter"
- "@auth/upstash-redis-adapter"
- "@next-auth/xata-adapter"
validations:
required: true

View File

@@ -16,7 +16,7 @@ mikro-orm:
- "@next-auth/mikro-orm-adapter"
mongodb:
- "@next-auth/mongodb-adapter"
- "@auth/mongodb-adapter"
neo4j:
- "@next-auth/neo4j-adapter"
@@ -37,7 +37,7 @@ typeorm:
- "@auth/typeorm-adapter"
upstash-redis:
- "@next-auth/upstash-redis-adapter"
- "@auth/upstash-redis-adapter"
xata:
- "@next-auth/xata-adapter"

View File

@@ -91,12 +91,12 @@ Finally, we'll need to set up a database adapter to store verification tokens th
An **Adapter** in Auth.js connects your application to whatever database or backend system you want to use to store data for users, their accounts, sessions, etc...
For this tutorial, we're going to use the **MongoDB** adapter, other any of the other adapters will work just fine.
For this tutorial, we're going to use the **MongoDB** adapter, but any of the other adapters will work just fine.
First, let's start by installing the adapter package:
```bash npm2yarn2pnpm
npm install -D @next-auth/mongodb-adapter mongodb
npm install -D @auth/mongodb-adapter mongodb
```
and create a simple MongoDB client:
@@ -142,7 +142,7 @@ And now let's reference this new adapter from our Auth.js configuration file:
```diff title="pages/api/auth/[...nextauth].ts"
import NextAuth from "next-auth"
import EmailProvider from "next-auth/providers/email"
+ import { MongoDBAdapter } from "@next-auth/mongodb-adapter"
+ import { MongoDBAdapter } from "@auth/mongodb-adapter"
+ import clientPromise from "../../../lib/mongodb/client"
export default NextAuth({

View File

@@ -22,11 +22,18 @@ Next you will have to create some configuration files for Cypress.
First, the primary cypress config:
```js title="cypress.json"
{
"baseUrl": "http://localhost:3000",
"chromeWebSecurity": false
}
```ts title="cypress.config.ts"
import { defineConfig } from 'cypress'
export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
chromeWebSecurity: false,
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
})
```
This initial Cypress config will tell Cypress where to find your site on initial launch as well as allow it to open up URLs at domains that aren't your page, for example to be able to login to a social provider.
@@ -46,14 +53,24 @@ You must change the login credentials you want to use, but you can also redefine
Third, if you're using the `cypress-social-login` plugin, you must add this to your `/cypress/plugins/index.js` file like so:
```js title="cypress/plugins/index.js"
const { GoogleSocialLogin } = require("cypress-social-logins").plugins
```js title="cypress.config.ts" {3-4,10-14}
import { defineConfig } from 'cypress'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { GoogleSocialLogin } = require('cypress-social-logins').plugins
export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
chromeWebSecurity: false,
setupNodeEvents(on, config) {
on('task', {
GoogleSocialLogin,
})
},
},
})
module.exports = (on, config) => {
on("task", {
GoogleSocialLogin: GoogleSocialLogin,
})
}
```
Finally, you can also add the following npm scripts to your `package.json`:

View File

@@ -8,14 +8,14 @@
</a>
<h3 align="center"><b>MongoDB Adapter</b> - NextAuth.js / Auth.js</a></h3>
<p align="center" style="align: center;">
<a href="https://npm.im/@next-auth/mongodb-adapter">
<a href="https://npm.im/@auth/mongodb-adapter">
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
</a>
<a href="https://npm.im/@next-auth/mongodb-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@next-auth/mongodb-adapter?color=green&label=@next-auth/mongodb-adapter&style=flat-square">
<a href="https://npm.im/@auth/mongodb-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@auth/mongodb-adapter?color=green&label=@auth/mongodb-adapter&style=flat-square">
</a>
<a href="https://www.npmtrends.com/@next-auth/mongodb-adapter">
<img src="https://img.shields.io/npm/dm/@next-auth/mongodb-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
<a href="https://www.npmtrends.com/@auth/mongodb-adapter">
<img src="https://img.shields.io/npm/dm/@auth/mongodb-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
</a>
<a href="https://github.com/nextauthjs/next-auth/stargazers">
<img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square" alt="Github Stars" />

View File

@@ -1,14 +1,26 @@
{
"name": "@next-auth/mongodb-adapter",
"version": "1.1.3",
"description": "mongoDB adapter for next-auth.",
"name": "@auth/mongodb-adapter",
"version": "1.0.0",
"description": "MongoDB adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
"bugs": {
"url": "https://github.com/nextauthjs/next-auth/issues"
},
"author": "Balázs Orbán <info@balazsorban.com>",
"main": "dist/index.js",
"type": "module",
"types": "./index.d.ts",
"files": [
"*.js",
"*.d.ts*",
"src"
],
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
}
},
"license": "ISC",
"keywords": [
"next-auth",
@@ -26,20 +38,17 @@
"test:watch": "./tests/test.sh -w",
"build": "tsc"
},
"files": [
"README.md",
"dist"
],
"dependencies": {
"@auth/core": "workspace:*"
},
"peerDependencies": {
"mongodb": "^5 || ^4",
"next-auth": "^4"
"mongodb": "^5 || ^4"
},
"devDependencies": {
"@next-auth/adapter-test": "workspace:*",
"@next-auth/tsconfig": "workspace:*",
"jest": "^27.4.3",
"mongodb": "^5.1.0",
"next-auth": "workspace:*"
"mongodb": "^5.1.0"
},
"jest": {
"preset": "@next-auth/adapter-test/jest"

View File

@@ -9,10 +9,10 @@
* ## Installation
*
* ```bash npm2yarn2pnpm
* npm install next-auth @next-auth/mongodb-adapter mongodb
* npm install @auth/mongodb-adapter mongodb
* ```
*
* @module @next-auth/mongodb-adapter
* @module @auth/mongodb-adapter
*/
import { ObjectId } from "mongodb"
@@ -22,7 +22,7 @@ import type {
AdapterAccount,
AdapterSession,
VerificationToken,
} from "next-auth/adapters"
} from "@auth/core/adapters"
import type { MongoClient } from "mongodb"
/** This is the interface of the MongoDB adapter options. */
@@ -132,7 +132,7 @@ export function _id(hex?: string) {
*
* ```js
* import NextAuth from "next-auth"
* import { MongoDBAdapter } from "@next-auth/mongodb-adapter"
* import { MongoDBAdapter } from "@auth/mongodb-adapter"
* import clientPromise from "../../../lib/mongodb"
*
* // For more information on each option (and a full list of options) go to

View File

@@ -1,8 +1,25 @@
{
"extends": "@next-auth/tsconfig/tsconfig.adapters.json",
"extends": "@next-auth/tsconfig/tsconfig.base.json",
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"isolatedModules": true,
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"outDir": ".",
"rootDir": "src",
"outDir": "dist"
"skipDefaultLibCheck": true,
"strictNullChecks": true,
"stripInternal": true,
"declarationMap": true,
"declaration": true
},
"exclude": ["tests", "dist", "jest.config.js"]
}
"include": [
"src/**/*"
],
"exclude": [
"*.js",
"*.d.ts",
]
}

View File

@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN}

View File

@@ -8,14 +8,14 @@
</a>
<h3 align="center"><b>Upstash Redis Adapter</b> - NextAuth.js / Auth.js</a></h3>
<p align="center" style="align: center;">
<a href="https://npm.im/@next-auth/upstash-redis-adapter">
<a href="https://npm.im/@auth/upstash-redis-adapter">
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
</a>
<a href="https://npm.im/@next-auth/upstash-redis-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@next-auth/upstash-redis-adapter?color=green&label=@next-auth/upstash-redis-adapter&style=flat-square">
<a href="https://npm.im/@auth/upstash-redis-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@auth/upstash-redis-adapter?color=green&label=@auth/upstash-redis-adapter&style=flat-square">
</a>
<a href="https://www.npmtrends.com/@next-auth/upstash-redis-adapter">
<img src="https://img.shields.io/npm/dm/@next-auth/upstash-redis-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
<a href="https://www.npmtrends.com/@auth/upstash-redis-adapter">
<img src="https://img.shields.io/npm/dm/@auth/upstash-redis-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
</a>
<a href="https://github.com/nextauthjs/next-auth/stargazers">
<img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square" alt="Github Stars" />

View File

@@ -1,14 +1,26 @@
{
"name": "@next-auth/upstash-redis-adapter",
"version": "3.0.4",
"description": "Upstash adapter for next-auth. It uses Upstash's connectionless (HTTP based) Redis client.",
"name": "@auth/upstash-redis-adapter",
"version": "1.0.0",
"description": "Upstash adapter for Auth.js.",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
"bugs": {
"url": "https://github.com/nextauthjs/next-auth/issues"
},
"author": "github.com/kay-is",
"main": "dist/index.js",
"type": "module",
"types": "./index.d.ts",
"files": [
"*.js",
"*.d.ts*",
"src"
],
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
}
},
"license": "ISC",
"keywords": [
"next-auth",
@@ -25,13 +37,11 @@
"test": "jest",
"build": "tsc"
},
"files": [
"README.md",
"dist"
],
"dependencies": {
"@auth/core": "workspace:*"
},
"peerDependencies": {
"@upstash/redis": "^1.0.1",
"next-auth": "^4"
"@upstash/redis": "^1.0.1"
},
"devDependencies": {
"@next-auth/adapter-test": "workspace:*",
@@ -43,9 +53,6 @@
"jest": "^27.4.3",
"next-auth": "workspace:*"
},
"dependencies": {
"uuid": "^8.3.2"
},
"jest": {
"preset": "@next-auth/adapter-test/jest"
}

View File

@@ -9,10 +9,10 @@
* ## Installation
*
* ```bash npm2yarn2pnpm
* npm install @upstash/redis @next-auth/upstash-redis-adapter
* npm install @upstash/redis @auth/upstash-redis-adapter
* ```
*
* @module @next-auth/upstash-redis-adapter
* @module @auth/upstash-redis-adapter
*/
import type {
Adapter,
@@ -20,11 +20,9 @@ import type {
AdapterAccount,
AdapterSession,
VerificationToken,
} from "next-auth/adapters"
} from "@auth/core/adapters"
import type { Redis } from "@upstash/redis"
import { v4 as uuid } from "uuid"
/** This is the interface of the Upstash Redis adapter options. */
export interface UpstashRedisAdapterOptions {
/**
@@ -93,7 +91,7 @@ export function hydrateDates(json: object) {
* ```javascript title="pages/api/auth/[...nextauth].js"
* import NextAuth from "next-auth"
* import GoogleProvider from "next-auth/providers/google"
* import { UpstashRedisAdapter } from "@next-auth/upstash-redis-adapter"
* import { UpstashRedisAdapter } from "@auth/upstash-redis-adapter"
* import upstashRedisClient from "@upstash/redis"
*
* const redis = upstashRedisClient(
@@ -217,7 +215,7 @@ export function UpstashRedisAdapter(
return {
async createUser(user) {
const id = uuid()
const id = crypto.randomUUID()
// TypeScript thinks the emailVerified field is missing
// but all fields are copied directly from user, so it's there
return await setUser(id, { ...user, id })

View File

@@ -4,6 +4,8 @@ import { runBasicTests } from "@next-auth/adapter-test"
import { hydrateDates, UpstashRedisAdapter } from "../src"
import "dotenv/config"
globalThis.crypto ??= require("node:crypto").webcrypto
if (!process.env.UPSTASH_REDIS_URL || !process.env.UPSTASH_REDIS_KEY) {
test("Skipping UpstashRedisAdapter tests, since required environment variables aren't available", () => {
expect(true).toBe(true)
@@ -27,6 +29,7 @@ const client = new Redis({
runBasicTests({
adapter: UpstashRedisAdapter(client, { baseKeyPrefix: "testApp:" }),
db: {
disconnect: client.flushdb,
async user(id: string) {
const data = await client.get<object>(`testApp:user:${id}`)
if (!data) return null
@@ -48,7 +51,7 @@ runBasicTests({
},
async verificationToken(where) {
const data = await client.get<object>(
`testApp:user:token:${where.identifier}`
`testApp:user:token:${where.identifier}:${where.token}`
)
if (!data) return null
return hydrateDates(data)

View File

@@ -1,8 +1,25 @@
{
"extends": "@next-auth/tsconfig/tsconfig.adapters.json",
"extends": "@next-auth/tsconfig/tsconfig.base.json",
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"isolatedModules": true,
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"outDir": ".",
"rootDir": "src",
"outDir": "dist"
"skipDefaultLibCheck": true,
"strictNullChecks": true,
"stripInternal": true,
"declarationMap": true,
"declaration": true
},
"exclude": ["tests", "dist", "jest.config.js"]
}
"include": [
"src/**/*"
],
"exclude": [
"*.js",
"*.d.ts",
]
}

View File

@@ -1,6 +1,6 @@
{
"name": "@auth/core",
"version": "0.8.1",
"version": "0.8.2",
"description": "Authentication for the Web.",
"keywords": [
"authentication",

View File

@@ -159,8 +159,17 @@ export class SessionStore {
* The JWT Session or database Session ID
* constructed from the cookie chunks.
*/
get value() {
return Object.values(this.#chunks)?.join("")
get value() {
// Sort the chunks by their keys before joining
const sortedKeys = Object.keys(this.#chunks).sort((a, b) => {
const aSuffix = parseInt(a.split(".")[1] || "0");
const bSuffix = parseInt(b.split(".")[1] || "0");
return aSuffix - bSuffix;
});
// Use the sorted keys to join the chunks in the correct order
return sortedKeys.map(key => this.#chunks[key]).join("");
}
/** Given a cookie, return a list of cookies, chunked to fit the allowed cookie size. */

View File

@@ -1,6 +1,6 @@
{
"name": "@auth/sveltekit",
"version": "0.3.1",
"version": "0.3.2",
"description": "Authentication for SvelteKit.",
"keywords": [
"authentication",

View File

@@ -63,7 +63,7 @@ export async function signIn<
const data = await res.clone().json()
const error = new URL(data.url).searchParams.get("error")
if (redirect || !isSupportingReturn || !error) {
if (redirect || !isSupportingReturn) {
// TODO: Do not redirect for Credentials and Email providers by default in next major
window.location.href = data.url ?? callbackUrl
// If url contains a hash, the browser does not reload the page. We reload manually

9
pnpm-lock.yaml generated
View File

@@ -352,17 +352,18 @@ importers:
packages/adapter-mongodb:
specifiers:
'@auth/core': workspace:*
'@next-auth/adapter-test': workspace:*
'@next-auth/tsconfig': workspace:*
jest: ^27.4.3
mongodb: ^5.1.0
next-auth: workspace:*
dependencies:
'@auth/core': link:../core
devDependencies:
'@next-auth/adapter-test': link:../adapter-test
'@next-auth/tsconfig': link:../tsconfig
jest: 27.5.1
mongodb: 5.1.0
next-auth: link:../next-auth
packages/adapter-neo4j:
specifiers:
@@ -504,6 +505,7 @@ importers:
packages/adapter-upstash-redis:
specifiers:
'@auth/core': workspace:*
'@next-auth/adapter-test': workspace:*
'@next-auth/tsconfig': workspace:*
'@types/uuid': ^8.3.3
@@ -512,9 +514,8 @@ importers:
isomorphic-fetch: 3.0.0
jest: ^27.4.3
next-auth: workspace:*
uuid: ^8.3.2
dependencies:
uuid: 8.3.2
'@auth/core': link:../core
devDependencies:
'@next-auth/adapter-test': link:../adapter-test
'@next-auth/tsconfig': link:../tsconfig

View File

@@ -47,7 +47,7 @@
"e2e": {
"outputs": ["playwright-report/**"]
},
"@next-auth/upstash-redis-adapter#test": {
"@auth/upstash-redis-adapter#test": {
"env": ["UPSTASH_REDIS_KEY", "UPSTASH_REDIS_URL"]
},
"docs#dev": {
@@ -60,13 +60,13 @@
"@next-auth/fauna-adapter#build",
"@next-auth/firebase-adapter#build",
"@next-auth/mikro-orm-adapter#build",
"@next-auth/mongodb-adapter#build",
"@auth/mongodb-adapter#build",
"@next-auth/neo4j-adapter#build",
"@next-auth/pouchdb-adapter#build",
"@next-auth/sequelize-adapter#build",
"@next-auth/supabase-adapter#build",
"@auth/typeorm-adapter#build",
"@next-auth/upstash-redis-adapter#build",
"@auth/upstash-redis-adapter#build",
"@next-auth/xata-adapter#build",
"^build",
"next-auth#build"
@@ -83,13 +83,13 @@
"@next-auth/fauna-adapter#build",
"@next-auth/firebase-adapter#build",
"@next-auth/mikro-orm-adapter#build",
"@next-auth/mongodb-adapter#build",
"@auth/mongodb-adapter#build",
"@next-auth/neo4j-adapter#build",
"@next-auth/pouchdb-adapter#build",
"@next-auth/sequelize-adapter#build",
"@next-auth/supabase-adapter#build",
"@auth/typeorm-adapter#build",
"@next-auth/upstash-redis-adapter#build",
"@auth/upstash-redis-adapter#build",
"@next-auth/xata-adapter#build",
"^build",
"next-auth#build"