-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from kameiryohei/try-auth-ssr
Supabaseの認証をサーバー側で実現し、依存箇所を修正
- Loading branch information
Showing
55 changed files
with
1,690 additions
and
855 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import prisma from "utils/prisma/prismaClient"; | ||
|
||
//サーバーサイドからプロフィール情報を取得するAPI(動作確認済み) | ||
export const GET = async (req: NextRequest) => { | ||
try { | ||
await prisma.$connect(); | ||
const auth_id: string = req.url.split("/auth/")[1]; | ||
const user = await prisma.user.findUnique({ | ||
where: { auth_id }, | ||
select: { | ||
id: true, | ||
auth_id: true, | ||
name: true, | ||
email: true, | ||
university: true, | ||
faculty: true, | ||
department: true, | ||
grade: true, | ||
}, | ||
}); | ||
return NextResponse.json({ message: "Success", user }, { status: 200 }); | ||
} catch (error) { | ||
return NextResponse.json({ message: "Error", error }, { status: 500 }); | ||
} finally { | ||
await prisma.$disconnect(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { type EmailOtpType } from "@supabase/supabase-js"; | ||
import { type NextRequest } from "next/server"; | ||
|
||
import { redirect } from "next/navigation"; | ||
import { createClient } from "utils/supabase/sever"; | ||
|
||
export async function GET(request: NextRequest) { | ||
const { searchParams } = new URL(request.url); | ||
const token_hash = searchParams.get("token_hash"); | ||
const type = searchParams.get("type") as EmailOtpType | null; | ||
const next = searchParams.get("next") ?? "/"; | ||
|
||
if (token_hash && type) { | ||
const supabase = createClient(); | ||
|
||
const { error } = await supabase.auth.verifyOtp({ | ||
type, | ||
token_hash, | ||
}); | ||
if (!error) { | ||
// redirect user to specified redirect URL or root of app | ||
redirect(next); | ||
} | ||
} | ||
|
||
// redirect the user to an error page with some instructions | ||
redirect("/error"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { NextResponse } from "next/server"; | ||
import prisma from "utils/prisma/prismaClient"; | ||
|
||
// ユーザーが投稿したレビューを取得するAPI | ||
export async function GET( | ||
req: Request, | ||
{ params }: { params: { id: string } } | ||
) { | ||
const auth_id = params.id; | ||
const data = await prisma.user.findUnique({ | ||
where: { | ||
auth_id: auth_id, | ||
}, | ||
select: { | ||
posts: { | ||
select: { | ||
id: true, | ||
title: true, | ||
content: true, | ||
createdAt: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
return NextResponse.json(data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.