|
1 | 1 | import { Account, User, Awaitable } from "." |
2 | | -import type { Adapter as FutureAdapter } from "./futureAdapter" |
3 | 2 |
|
4 | 3 | export interface AdapterUser extends User { |
5 | 4 | id: string |
@@ -60,55 +59,61 @@ export interface VerificationToken { |
60 | 59 | * [Adapters Overview](https://next-auth.js.org/adapters/overview) | |
61 | 60 | * [Create a custom adapter](https://next-auth.js.org/tutorials/creating-a-database-adapter) |
62 | 61 | */ |
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> |
69 | 83 | /** Using the provider id and the id of the user for a specific account, get the user. */ |
70 | | - getUserByAccount?: ( |
| 84 | + getUserByAccount: ( |
71 | 85 | providerAccountId: Pick<AdapterAccount, "provider" | "providerAccountId"> |
72 | 86 | ) => 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> |
76 | 88 | /** @todo Implement */ |
77 | 89 | deleteUser?: ( |
78 | 90 | userId: string |
79 | 91 | ) => 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> |
85 | 95 | /** @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> |
94 | 99 | /** Creates a session for the user and returns it. */ |
95 | | - createSession?: (session: { |
| 100 | + createSession: (session: { |
96 | 101 | sessionToken: string |
97 | 102 | userId: string |
98 | 103 | expires: Date |
99 | 104 | }) => Awaitable<AdapterSession> |
100 | | - getSessionAndUser?: ( |
| 105 | + getSessionAndUser: ( |
101 | 106 | sessionToken: string |
102 | 107 | ) => Awaitable<{ session: AdapterSession; user: AdapterUser } | null> |
103 | | - updateSession?: ( |
| 108 | + updateSession: ( |
104 | 109 | session: Partial<AdapterSession> & Pick<AdapterSession, "sessionToken"> |
105 | 110 | ) => Awaitable<AdapterSession | null | undefined> |
106 | 111 | /** |
107 | 112 | * Deletes a session from the database. |
108 | 113 | * It is preferred that this method also returns the session |
109 | 114 | * that is being deleted for logging purposes. |
110 | 115 | */ |
111 | | - deleteSession?: ( |
| 116 | + deleteSession: ( |
112 | 117 | sessionToken: string |
113 | 118 | ) => Promise<void> | Awaitable<AdapterSession | null | undefined> |
114 | 119 | createVerificationToken?: ( |
|
0 commit comments