LoginSignup
1
0

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 ライフを

1
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
1
0