Compare commits

...

2 Commits

Author SHA1 Message Date
Balázs Orbán
172ad02f8c fix(ts): move AppProvider out of internals (#1800)
* fix(ts): move AppProvider out of internals

* fix(ts): fix import paths
2021-04-21 23:09:42 +02:00
Balázs Orbán
eed0001524 fix(ts): adjust properties on default interfaces (#1794)
* fix(ts): adjust properties on default interfaces

* fix(ts): make expires also optional

* fix(ts): don't require default session/jwt fields

* fix(ts): make all default fields optional
2021-04-21 17:17:38 +02:00
7 changed files with 26 additions and 20 deletions

2
types/adapters.d.ts vendored
View File

@@ -1,7 +1,7 @@
import { AppOptions } from "./internals"
import { ConnectionOptions, EntitySchema } from "typeorm"
import { User } from "."
import { AppProvider } from "./internals/providers"
import { AppProvider } from "./providers"
export interface Profile {
id: string

15
types/index.d.ts vendored
View File

@@ -364,6 +364,15 @@ export interface PagesOptions {
newUser?: string
}
export interface DefaultSession extends Record<string, unknown> {
user?: {
name?: string | null
email?: string | null
image?: string | null
}
expires?: string
}
/**
* Returned by `useSession`, `getSession`, returned by the `session` callback
* and also the shape received as a prop on the `Provider` React Context
@@ -373,11 +382,7 @@ export interface PagesOptions {
* [`Provider`](https://next-auth.js.org/getting-started/client#provider) |
* [`session` callback](https://next-auth.js.org/configuration/callbacks#jwt-callback)
*/
export interface Session extends Record<string, unknown> {
user?: User
accessToken?: string
expires: string
}
export interface Session extends Record<string, unknown>, DefaultSession {}
/** [Documentation](https://next-auth.js.org/configuration/options#session) */
export interface SessionOptions {

View File

@@ -1,6 +1,6 @@
import { NextApiRequest, NextApiResponse } from "./utils"
import { NextAuthOptions } from ".."
import { AppProvider } from "./providers"
import { AppProvider } from "../providers"
/** Options that are the same both in internal and user provided options. */
export type NextAuthSharedOptions =

View File

@@ -1,6 +0,0 @@
import { CommonProviderOptions } from "../providers"
export interface AppProvider extends CommonProviderOptions {
signinUrl: string
callbackUrl: string
}

13
types/jwt.d.ts vendored
View File

@@ -1,16 +1,19 @@
import { JWT as JoseJWT, JWE } from "jose"
import { NextApiRequest } from "./internals/utils"
export interface DefaultJWT extends Record<string, unknown> {
name?: string | null
email?: string | null
picture?: string | null
sub?: string
}
/**
* Returned by the `jwt` callback and `getToken`, when using JWT sessions
*
* [`jwt` callback](https://next-auth.js.org/configuration/callbacks#jwt-callback) | [`getToken`](https://next-auth.js.org/tutorials/securing-pages-and-api-routes#using-gettoken)
*/
export interface JWT extends Record<string, unknown> {
name?: string | null
email?: string | null
picture?: string | null
}
export interface JWT extends Record<string, unknown>, DefaultJWT {}
export interface JWTEncodeParams {
token?: JWT

View File

@@ -161,6 +161,11 @@ export type AppProviders = Array<
Provider | ReturnType<BuiltInProviders[keyof BuiltInProviders]>
>
export interface AppProvider extends CommonProviderOptions {
signinUrl: string
callbackUrl: string
}
declare const Providers: BuiltInProviders
export default Providers

View File

@@ -1,4 +1,4 @@
import Providers, { OAuthConfig } from "next-auth/providers"
import Providers, { AppProvider, OAuthConfig } from "next-auth/providers"
import {
Adapter,
EmailAppProvider,
@@ -12,7 +12,6 @@ import * as JWTType from "next-auth/jwt"
import { Socket } from "net"
import { NextApiRequest, NextApiResponse } from "internals/utils"
import { AppOptions } from "internals"
import { AppProvider } from "internals/providers"
const req: NextApiRequest = Object.assign(new IncomingMessage(new Socket()), {
query: {},