Skip to content

Commit

Permalink
fix(ts): make Profile/User interfaces overridable (#1801)
Browse files Browse the repository at this point in the history
* fix(ts): create DefaultUser interface

* fix(ts): fix TypeORMUserModel

* fix(ts): create DefaultProfile
  • Loading branch information
balazsorban44 committed Apr 21, 2021
1 parent 172ad02 commit 34f334a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions types/adapters.d.ts
Expand Up @@ -204,6 +204,7 @@ declare class TypeORMUserModel implements User {
image?: string,
emailVerified?: Date
)
[x: string]: unknown
}

declare class TypeORMSessionModel implements Session {
Expand Down
18 changes: 11 additions & 7 deletions types/index.d.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

1 comment on commit 34f334a

@vercel
Copy link

@vercel vercel bot commented on 34f334a Apr 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.