4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

前回AWS AmplifyのGen2のスターターテンプレートを使用して、Next.js (App Router) のアプリをデプロイしました。今回は、簡易なログインUIを追加したときの備忘録となります。

まとめ

  • Amplify が提供している Authenticator UI コンポーネントを使うと10分程度で認証画面を用意できる
  • 既存の Next.js(App Router)構成でもlayout.tsx を少し編集するだけで導入可能
  • とりあえず認証画面を用意したいときに便利

公式ドキュメント

公式のドキュメントは下記の通りです。

ログインUIを追加する

前回使ったAWS AmplifyのGen2のスターターテンプレートを編集していきます。
Amplifyが用意しているAuthenticator UI コンポーネントを使用してログインUIを実装します。

app/layout.tsxへ下記を追加するのみです。

下記をインポートし、

import { Authenticator } from "@aws-amplify/ui-react";
import "@aws-amplify/ui-react/styles.css";

{children}をで囲うだけです。

<Authenticator>
          {children}
 </Authenticator>
変更後の layout.tsx
"use client";

import outputs from "@/amplify_outputs.json";
import { Authenticator } from "@aws-amplify/ui-react";
import "@aws-amplify/ui-react/styles.css";
import { Amplify } from "aws-amplify";

import { Inter } from "next/font/google";
import "./app.css";

const inter = Inter({ subsets: ["latin"] });

Amplify.configure(outputs);

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <Authenticator>{children}</Authenticator>
      </body>
    </html>
  );
}

ここまでできたら実装は完了です。実行してみましょう。

npm run dev

ブラウザでアクセスすると、ログイン画面が表示されます。
Authenticator UI コンポーネントを使うことで、10分程度で認証画面を用意できました。

FireShot Capture 020 -  - [localhost].png

Create Account からメールアドレスとパスワードを設定すると、アカウントを作成できます。
作成したアカウントは Cognitoで確認できます。
スクリーンショット 2026-01-16 17.26.19.png

4
2
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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?