Skip to content

Commit 83a2047

Browse files
committed
chore: revert futureAdapter due to incompatibility
1 parent 2654af9 commit 83a2047

3 files changed

Lines changed: 33 additions & 458 deletions

File tree

packages/next-auth/src/adapters.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Account, User, Awaitable } from "."
2-
import type { Adapter as FutureAdapter } from "./futureAdapter"
32

43
export interface AdapterUser extends User {
54
id: string
@@ -60,55 +59,61 @@ export interface VerificationToken {
6059
* [Adapters Overview](https://next-auth.js.org/adapters/overview) |
6160
* [Create a custom adapter](https://next-auth.js.org/tutorials/creating-a-database-adapter)
6261
*/
63-
export interface Adapter {
64-
createUser?:
65-
| FutureAdapter["createUser"]
66-
| ((user: Omit<AdapterUser, "id">) => Awaitable<AdapterUser>)
67-
getUser?: (id: string) => Awaitable<AdapterUser | null>
68-
getUserByEmail?: (email: string) => Awaitable<AdapterUser | null>
62+
export type Adapter<WithVerificationToken = boolean> = DefaultAdapter &
63+
(WithVerificationToken extends true
64+
? {
65+
createVerificationToken: (
66+
verificationToken: VerificationToken
67+
) => Awaitable<VerificationToken | null | undefined>
68+
/**
69+
* Return verification token from the database
70+
* and delete it so it cannot be used again.
71+
*/
72+
useVerificationToken: (params: {
73+
identifier: string
74+
token: string
75+
}) => Awaitable<VerificationToken | null>
76+
}
77+
: {})
78+
79+
export interface DefaultAdapter {
80+
createUser: (user: Omit<AdapterUser, "id">) => Awaitable<AdapterUser>
81+
getUser: (id: string) => Awaitable<AdapterUser | null>
82+
getUserByEmail: (email: string) => Awaitable<AdapterUser | null>
6983
/** Using the provider id and the id of the user for a specific account, get the user. */
70-
getUserByAccount?: (
84+
getUserByAccount: (
7185
providerAccountId: Pick<AdapterAccount, "provider" | "providerAccountId">
7286
) => Awaitable<AdapterUser | null>
73-
updateUser?: (
74-
user: Partial<AdapterUser> & Pick<AdapterUser, "id">
75-
) => Awaitable<AdapterUser>
87+
updateUser: (user: Partial<AdapterUser> & Pick<AdapterUser, "id">) => Awaitable<AdapterUser>
7688
/** @todo Implement */
7789
deleteUser?: (
7890
userId: string
7991
) => Promise<void> | Awaitable<AdapterUser | null | undefined>
80-
linkAccount?:
81-
| FutureAdapter["linkAccount"]
82-
| ((
83-
account: AdapterAccount,
84-
) => Promise<void> | Awaitable<AdapterAccount | null | undefined>)
92+
linkAccount: (
93+
account: AdapterAccount
94+
) => Promise<void> | Awaitable<AdapterAccount | null | undefined>
8595
/** @todo Implement */
86-
unlinkAccount?:
87-
| FutureAdapter["unlinkAccount"]
88-
| ((
89-
providerAccountId: Pick<
90-
AdapterAccount,
91-
"provider" | "providerAccountId"
92-
>,
93-
) => Promise<void> | Awaitable<AdapterAccount | undefined>)
96+
unlinkAccount?: (
97+
providerAccountId: Pick<AdapterAccount, "provider" | "providerAccountId">
98+
) => Promise<void> | Awaitable<AdapterAccount | undefined>
9499
/** Creates a session for the user and returns it. */
95-
createSession?: (session: {
100+
createSession: (session: {
96101
sessionToken: string
97102
userId: string
98103
expires: Date
99104
}) => Awaitable<AdapterSession>
100-
getSessionAndUser?: (
105+
getSessionAndUser: (
101106
sessionToken: string
102107
) => Awaitable<{ session: AdapterSession; user: AdapterUser } | null>
103-
updateSession?: (
108+
updateSession: (
104109
session: Partial<AdapterSession> & Pick<AdapterSession, "sessionToken">
105110
) => Awaitable<AdapterSession | null | undefined>
106111
/**
107112
* Deletes a session from the database.
108113
* It is preferred that this method also returns the session
109114
* that is being deleted for logging purposes.
110115
*/
111-
deleteSession?: (
116+
deleteSession: (
112117
sessionToken: string
113118
) => Promise<void> | Awaitable<AdapterSession | null | undefined>
114119
createVerificationToken?: (

packages/next-auth/src/core/lib/callback-handler.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export default async function callbackHandler(params: {
104104
} else {
105105
const { id: _, ...newUser } = { ...profile, emailVerified: new Date() }
106106
// Create user account if there isn't one for the email address already
107-
// @ts-expect-error see adapters.ts' FutureAdapter["createUser"]
108107
user = await createUser(newUser)
109108
await events.createUser?.({ user })
110109
isNewUser = true
@@ -154,7 +153,6 @@ export default async function callbackHandler(params: {
154153
if (user) {
155154
// If the user is already signed in and the OAuth account isn't already associated
156155
// with another user account then we can go ahead and link the accounts safely.
157-
// @ts-expect-error see adapters.ts' FutureAdapter["linkAccount"]
158156
await linkAccount({ ...account, userId: user.id })
159157
await events.linkAccount?.({ user, account, profile })
160158

@@ -208,12 +206,10 @@ export default async function callbackHandler(params: {
208206
// create a new account for the user, link it to the OAuth acccount and
209207
// create a new session for them so they are signed in with it.
210208
const { id: _, ...newUser } = { ...profile, emailVerified: null }
211-
// @ts-expect-error see adapters.ts' FutureAdapter["createUser"]
212209
user = await createUser(newUser)
213210
}
214211
await events.createUser?.({ user })
215212

216-
// @ts-expect-error see adapters.ts' FutureAdapter["linkAccount"]
217213
await linkAccount({ ...account, userId: user.id })
218214
await events.linkAccount?.({ user, account, profile })
219215

0 commit comments

Comments
 (0)