Compare commits

...

2 Commits

Author SHA1 Message Date
Balázs Orbán
34f334a71d fix(ts): make Profile/User interfaces overridable (#1801)
* fix(ts): create DefaultUser interface

* fix(ts): fix TypeORMUserModel

* fix(ts): create DefaultProfile
2021-04-22 01:04:23 +02:00
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
6 changed files with 20 additions and 17 deletions

3
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
@@ -204,6 +204,7 @@ declare class TypeORMUserModel implements User {
image?: string,
emailVerified?: Date
)
[x: string]: unknown
}
declare class TypeORMSessionModel implements Session {

18
types/index.d.ts vendored
View File

@@ -251,14 +251,16 @@ export interface Account extends TokenSet, Record<string, unknown> {
type: string
}
/** The OAuth profile returned from your provider */
export interface Profile extends Record<string, unknown> {
export interface DefaultProfile {
sub?: string
name?: string
email?: string
image?: string
}
/** The OAuth profile returned from your provider */
export interface Profile extends Record<string, unknown>, DefaultProfile {}
/** [Documentation](https://next-auth.js.org/configuration/callbacks) */
export interface CallbacksOptions<
P extends Record<string, unknown> = Profile,
@@ -391,6 +393,12 @@ export interface SessionOptions {
updateAge?: number
}
export interface DefaultUser {
name?: string | null
email?: string | null
image?: string | null
}
/**
* The shape of the returned object in the OAuth providers' `profile` callback,
* available in the `jwt` and `session` callbacks,
@@ -401,11 +409,7 @@ export interface SessionOptions {
* [`jwt` callback](https://next-auth.js.org/configuration/callbacks#jwt-callback) |
* [`profile` OAuth provider callback](https://next-auth.js.org/configuration/providers#using-a-custom-provider)
*/
export interface User {
name?: string | null
email?: string | null
image?: string | null
}
export interface User extends Record<string, unknown>, DefaultUser {}
declare function NextAuth(
req: NextApiRequest,

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
}

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: {},