-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add auth, timer session recording, and My Page dashboard #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+3,031
−18
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,22 @@ | ||
| import { auth } from '@/lib/auth' | ||
| import { headers } from 'next/headers' | ||
| import { redirect } from 'next/navigation' | ||
| import { MyPageContent } from '@/components/mypage/MyPageContent' | ||
|
|
||
| /** | ||
| * My Page - Protected server component. | ||
| * Validates session server-side and redirects to sign-in if unauthenticated. | ||
| * The proxy.ts middleware provides a lightweight cookie check as the first gate. | ||
| */ | ||
| // eslint-disable-next-line @laststance/react-next/all-memo -- async server components cannot be wrapped in React.memo | ||
| export default async function MyPage() { | ||
| const session = await auth.api.getSession({ | ||
| headers: await headers(), | ||
| }) | ||
|
|
||
| if (!session) { | ||
| redirect('/sign-in') | ||
| } | ||
|
|
||
| return <MyPageContent /> | ||
| } | ||
This file contains hidden or 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 hidden or 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,14 @@ | ||
| 'use client' | ||
|
|
||
| import { memo } from 'react' | ||
| import { SignInForm } from '@/components/auth/SignInForm' | ||
|
|
||
| const SignInPage = memo(function SignInPage() { | ||
| return ( | ||
| <main className="flex min-h-screen flex-col items-center justify-center p-8"> | ||
| <SignInForm /> | ||
| </main> | ||
| ) | ||
| }) | ||
|
|
||
| export default SignInPage |
This file contains hidden or 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,14 @@ | ||
| 'use client' | ||
|
|
||
| import { memo } from 'react' | ||
| import { SignUpForm } from '@/components/auth/SignUpForm' | ||
|
|
||
| const SignUpPage = memo(function SignUpPage() { | ||
| return ( | ||
| <main className="flex min-h-screen flex-col items-center justify-center p-8"> | ||
| <SignUpForm /> | ||
| </main> | ||
| ) | ||
| }) | ||
|
|
||
| export default SignUpPage |
This file contains hidden or 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,4 @@ | ||
| import { auth } from '@/lib/auth' | ||
| import { toNextJsHandler } from 'better-auth/next-js' | ||
|
|
||
| export const { GET, POST } = toNextJsHandler(auth) |
This file contains hidden or 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,85 @@ | ||
| import { NextRequest, NextResponse } from 'next/server' | ||
| import { headers } from 'next/headers' | ||
| import { eq, and } from 'drizzle-orm' | ||
| import { auth } from '@/lib/auth' | ||
| import { db } from '@/db' | ||
| import { timerSession } from '@/db/schema' | ||
|
|
||
| /** | ||
| * PATCH /api/timer-sessions/[id] - Update a timer session. | ||
| * Only allows updating note and durationSeconds. | ||
| * | ||
| * @param request - JSON body: { note?: string, durationSeconds?: number } | ||
| * @returns Updated timer session | ||
| */ | ||
| export async function PATCH( | ||
| request: NextRequest, | ||
| { params }: { params: Promise<{ id: string }> }, | ||
| ) { | ||
| const session = await auth.api.getSession({ | ||
| headers: await headers(), | ||
| }) | ||
|
|
||
| if (!session) { | ||
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| const { id } = await params | ||
| const body = (await request.json()) as { | ||
| note?: string | ||
| durationSeconds?: number | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const updated = await db | ||
| .update(timerSession) | ||
| .set({ | ||
| ...(body.note !== undefined && { note: body.note }), | ||
| ...(body.durationSeconds !== undefined && { | ||
| durationSeconds: body.durationSeconds, | ||
| }), | ||
| updatedAt: new Date(), | ||
| }) | ||
| .where( | ||
| and(eq(timerSession.id, id), eq(timerSession.userId, session.user.id)), | ||
| ) | ||
| .returning() | ||
|
|
||
| if (updated.length === 0) { | ||
| return NextResponse.json({ error: 'Not found' }, { status: 404 }) | ||
| } | ||
|
|
||
| return NextResponse.json(updated[0]) | ||
| } | ||
|
|
||
| /** | ||
| * DELETE /api/timer-sessions/[id] - Delete a timer session. | ||
| * | ||
| * @returns 204 No Content on success | ||
| */ | ||
| export async function DELETE( | ||
| _request: NextRequest, | ||
| { params }: { params: Promise<{ id: string }> }, | ||
| ) { | ||
| const session = await auth.api.getSession({ | ||
| headers: await headers(), | ||
| }) | ||
|
|
||
| if (!session) { | ||
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| const { id } = await params | ||
|
|
||
| const deleted = await db | ||
| .delete(timerSession) | ||
| .where( | ||
| and(eq(timerSession.id, id), eq(timerSession.userId, session.user.id)), | ||
| ) | ||
| .returning() | ||
|
|
||
| if (deleted.length === 0) { | ||
| return NextResponse.json({ error: 'Not found' }, { status: 404 }) | ||
| } | ||
|
|
||
| return new NextResponse(null, { status: 204 }) | ||
| } | ||
This file contains hidden or 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,72 @@ | ||
| import { NextRequest, NextResponse } from 'next/server' | ||
| import { headers } from 'next/headers' | ||
| import { eq, desc } from 'drizzle-orm' | ||
| import { nanoid } from 'nanoid' | ||
| import { auth } from '@/lib/auth' | ||
| import { db } from '@/db' | ||
| import { timerSession } from '@/db/schema' | ||
|
|
||
| /** | ||
| * GET /api/timer-sessions - List timer sessions for the authenticated user. | ||
| * | ||
| * @returns JSON array of timer sessions, ordered by completedAt descending | ||
| * | ||
| * @example | ||
| * // Response: [{ id: 'abc', durationSeconds: 300, completedAt: '2026-02-16T09:30:00Z', ... }] | ||
| */ | ||
| export async function GET() { | ||
| const session = await auth.api.getSession({ | ||
| headers: await headers(), | ||
| }) | ||
|
|
||
| if (!session) { | ||
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| const sessions = await db | ||
| .select() | ||
| .from(timerSession) | ||
| .where(eq(timerSession.userId, session.user.id)) | ||
| .orderBy(desc(timerSession.completedAt)) | ||
|
|
||
| return NextResponse.json(sessions) | ||
| } | ||
|
|
||
| /** | ||
| * POST /api/timer-sessions - Create a new timer session. | ||
| * | ||
| * @param request - JSON body: { durationSeconds: number, completedAt: string, soundPreset: string } | ||
| * @returns Created timer session | ||
| * | ||
| * @example | ||
| * // Request body: | ||
| * { "durationSeconds": 300, "completedAt": "2026-02-16T09:30:00Z", "soundPreset": "ascending-chime" } | ||
| */ | ||
| export async function POST(request: NextRequest) { | ||
| const session = await auth.api.getSession({ | ||
| headers: await headers(), | ||
| }) | ||
|
|
||
| if (!session) { | ||
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| const body = (await request.json()) as { | ||
| durationSeconds: number | ||
| completedAt: string | ||
| soundPreset: string | ||
| } | ||
|
|
||
| const newSession = await db | ||
| .insert(timerSession) | ||
| .values({ | ||
| id: nanoid(), | ||
| userId: session.user.id, | ||
| durationSeconds: body.durationSeconds, | ||
| completedAt: new Date(body.completedAt), | ||
| soundPreset: body.soundPreset, | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }) | ||
| .returning() | ||
|
|
||
| return NextResponse.json(newSession[0], { status: 201 }) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.