2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NextAuthでTypescriptの型エラーの修正

Posted at

NextAuthとTypescriptを同時に扱う際、エラーがなかなか解決できなかったのでその対応メモです。

解決案 型定義

エラーでVScodeに怒られる原因は型の定義がないことだと思うんで、単純に定義してあげます。

(手のかかる子ですね、Typescriptちゃんは( ´∀` ))

next-auth.d.ts
import NextAuth from "next-auth"

declare module "next-auth" {
  /**
   * Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
   */
  interface Session {
    user: {
      /** The user's postal address. */
      name: string,
      email: string,
      image: string | any,
    }
    id: string
  }
}

これはNextAuthのProviderにGitHubを設定している場合です。

他のパターンだとまた違うのであくまで参考ということで。

ではよきNextAuth&Typescript ライフを

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?