Compare commits

...

1 Commits

Author SHA1 Message Date
Balázs Orbán
6df0d04a1e fix(ts): tweak Adapter related types (#1914)
Contains the following squashed commits:

* fix(ts): make first adapter parameter non-optional
* fix(ts): make defaulted values non-optional internally
* test(ts): fix linting
2021-05-03 21:24:19 +02:00
4 changed files with 21 additions and 11 deletions

4
types/adapters.d.ts vendored
View File

@@ -118,13 +118,13 @@ export interface AdapterInstance<U = User, P = Profile, S = Session> {
* [Create a custom adapter](https://next-auth.js.org/tutorials/creating-a-database-adapter)
*/
export type Adapter<
C = Record<string, unknown>,
C = unknown,
O = Record<string, unknown>,
U = unknown,
P = unknown,
S = unknown
> = (
config?: C,
client: C,
options?: O
) => {
getAdapter(appOptions: AppOptions): Promise<AdapterInstance<U, P, S>>

10
types/index.d.ts vendored
View File

@@ -180,7 +180,7 @@ export interface NextAuthOptions {
*
* [Documentation](https://next-auth.js.org/configuration/options#theme) | [Pages documentation]("https://next-auth.js.org/configuration/pages")
*/
theme?: "auto" | "dark" | "light"
theme?: Theme
/**
* When set to `true` then all cookies set by NextAuth.js will only be accessible from HTTPS URLs.
* This option defaults to `false` on URLs that start with `http://` (e.g. http://localhost:3000) for developer convenience.
@@ -215,6 +215,14 @@ export interface NextAuthOptions {
cookies?: CookiesOptions
}
/**
* Change the theme of the built-in pages.
*
* [Documentation](https://next-auth.js.org/configuration/options#theme) |
* [Pages](https://next-auth.js.org/configuration/pages)
*/
export type Theme = "auto" | "dark" | "light"
/**
* Override any of the methods, and the rest will use the default logger.
*

View File

@@ -1,5 +1,5 @@
import { NextApiRequest, NextApiResponse } from "./utils"
import { NextAuthOptions } from ".."
import { LoggerInstance, NextAuthOptions, SessionOptions, Theme } from ".."
import { AppProvider } from "../providers"
/** Options that are the same both in internal and user provided options. */
@@ -9,12 +9,7 @@ export type NextAuthSharedOptions =
| "events"
| "callbacks"
| "cookies"
| "secret"
| "adapter"
| "theme"
| "debug"
| "logger"
| "session"
export interface AppOptions
extends Required<Pick<NextAuthOptions, NextAuthSharedOptions>> {
@@ -42,6 +37,11 @@ export interface AppOptions
provider?: AppProvider
csrfToken?: string
csrfTokenVerified?: boolean
secret: string
theme: Theme
debug: boolean
logger: LoggerInstance
session: Required<SessionOptions>
}
export interface NextAuthRequest extends NextApiRequest {

View File

@@ -65,7 +65,7 @@ const exampleVerificationRequest = {
expires: new Date(),
}
const MyAdapter: Adapter = () => {
const MyAdapter: Adapter<Record<string, unknown>> = () => {
return {
async getAdapter(appOptions: AppOptions) {
return {
@@ -131,6 +131,8 @@ const MyAdapter: Adapter = () => {
}
}
const client = {} // Create a fake db client
const allConfig: NextAuthTypes.NextAuthOptions = {
providers: [
Providers.Twitter({
@@ -190,7 +192,7 @@ const allConfig: NextAuthTypes.NextAuthOptions = {
return undefined
},
},
adapter: MyAdapter(),
adapter: MyAdapter(client),
useSecureCookies: true,
cookies: {
sessionToken: {