Skip to content

feat: nextauth v4に対応#10

Open
undo1037 wants to merge 4 commits intopixiv:mainfrom
undo1037:feat_nextauth_v4
Open

feat: nextauth v4に対応#10
undo1037 wants to merge 4 commits intopixiv:mainfrom
undo1037:feat_nextauth_v4

Conversation

@undo1037
Copy link
Copy Markdown
Contributor

@undo1037 undo1037 commented Apr 24, 2026

NextAuth v4に対応しました。
NextAuth v3→v4は破壊的変更を大量に含んでいます。 https://next-auth.js.org/getting-started/upgrade-v4

また一部パッケージのバージョンを上げています。
他のパッケージも順次上げたいですが、一旦NextAuthのみの対応とします。

Comment thread types/next-auth.d.ts
import { JWT } from "next-auth/jwt";

declare module "next-auth" {
interface Session {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Q: この辺りの各種interfaceはどこで利用しているものでしょうか?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

使っているのはpages/api/auth/[...nextauth].tsですね。この辺入れておかないと形エラーになってしまうので入れた気がします

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IMO: 分かりました。declare module "next-auth" が1つのファイルに複数あるメリットはないと思うので、まとめていただけるとありがたいです。

if (account?.accessToken) {
token.accessToken = account.access_token;
}
if (profile) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Q: JWTのtoken.idへの代入が消されていますが、これは不要になったのでしょうか?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

console.logで値を見ていたのですが、元からprofileにidは入っていなさそうだったので消しました。おそらく最初に実装していた際に、NextAuthのサンプルコードなどを参考にしていたのではないでしょうか?

ちなみにprofileに入りうるのは { data : CurrentUserSerializer, ... } のようなデータです

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

承知しました。確認ありがとうございます

@undo1037
Copy link
Copy Markdown
Contributor Author

conflictしてるっぽいんで rebaseします

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants