takasaki376 / ThoughtKeeper-web

0 stars 0 forks source link

ログイン中でない場合はログイン画面に遷移処理を各ページに実装しました #26

Closed yoko-at-home closed 3 months ago

yoko-at-home commented 3 months ago

ログイン中でない場合はログイン画面に遷移処理を各ページに実装しました。 重複部分を以下のようにカスタムフック化したかったのですが、上手くいきませんでした(呼び出し側でuseAuthUser()をインポートしてもログインページに遷移せず...)。このため重複コードが残っております。


import { redirect } from "next/navigation";
import { createClient } from "@/utils/supabase/server";

export default async function useAuthUser() {
  const supabase = createClient();
  const {
    data: { user },
  } = await supabase.auth.getUser();
  if (!user) {
    return redirect("/auth/login");
  }
}
vercel[bot] commented 3 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
thought-keeper-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 2, 2024 1:47pm
thought-keeper-web-4jir ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 2, 2024 1:47pm
takasaki376 commented 3 months ago

重複部分を以下のようにカスタムフック化したかったのですが、上手くいきませんでした(呼び出し側でuseAuthUser() をインポートしてもログインページに遷移せず...)。このため重複コードが残っております。

layout.tsxとかで、ログインページに遷移するのはどうでしょうか。