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

Auth.js v5とnext-intlを組み合わせてmiddlewareを構築する方法

Last updated at Posted at 2024-12-29

Auth.jsのv5-betaと、next-intlを組み合わせてmiddlewareを書く方法が載ってなかったのでメモを残します。

import { auth } from '@/auth';
import { routing } from '@/i18n/routing';
import createMiddleware from 'next-intl/middleware';

const handleI18nRouting = createMiddleware(routing);
export default auth(handleI18nRouting);

export const config = {
  matcher: ['/((?!api|_next|.*\\..*).*)'],
};

なお、authは以下。詳しい書き方はこちら

export const { handlers, signIn, signOut, auth } = NextAuth({
  // ...
});

また、routingは以下。詳しい書き方はこちら

import { createNavigation } from 'next-intl/navigation';
import { defineRouting } from 'next-intl/routing';

export const routing = defineRouting({
  // A list of all locales that are supported
  locales: ['en', 'ja'],
  // Used when no locale matches
  defaultLocale: 'ja',
});

export type Locale = (typeof routing.locales)[number];

// Lightweight wrappers around Next.js' navigation APIs
// that will consider the routing configuration
export const { Link, redirect, usePathname, useRouter, getPathname } =
  createNavigation(routing);

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