Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/AvatarMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function AvatarMenu() {
return (
<button
onClick={() => {
authClient.signIn.social({ provider: 'github' }).catch(throwToBoundary)
authClient.signIn.social({ provider: 'github', callbackURL: '/profile' }).catch(throwToBoundary)
}}
>
Sign in via GitHub
Expand Down
10 changes: 7 additions & 3 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { type Route } from 'next'
import Link from 'next/link'
import { useSearchParams } from 'next/navigation'
import { useRouter, useSearchParams } from 'next/navigation'

import authClient from '@/lib/client/auth'
import { useServerAction, useThrowToBoundary } from '@/lib/client/util'
Expand Down Expand Up @@ -31,10 +31,14 @@ function errorParamToMsg(e: string, cfg: Config): string {

export default function Root() {
const cfg = useConfigCtx()
const router = useRouter()
const session = authClient.useSession()
const error = useSearchParams().get('error')
const { throwToBoundary } = useThrowToBoundary()
const [_, devLoginAction] = useServerAction(loginDevUser, () => session.refetch())
const [_, devLoginAction] = useServerAction(loginDevUser, async () => {
await session.refetch()
router.replace('/profile')
})

return (
<>
Expand All @@ -57,7 +61,7 @@ export default function Root() {
disabled={!cfg.hasGithubAuth}
title={!cfg.hasGithubAuth ? 'Ask your administrator to set up GitHub authentication.' : undefined}
onClick={() => {
authClient.signIn.social({ provider: 'github' }).catch(throwToBoundary)
authClient.signIn.social({ provider: 'github', callbackURL: '/profile' }).catch(throwToBoundary)
}}
>
GitHub
Expand Down
9 changes: 9 additions & 0 deletions src/app/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { redirect } from 'next/navigation'

import { requireAuth } from '@/lib/server/auth'

export default async function UserProfileForward() {
const auth = await requireAuth()
if (auth.user.name === 'profile') throw new Error('Unsupported username')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this rather be prevented during sign-up, in the better-auth hook for validating a new user profile? On that note we should also forbid other route names like 'setup'.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And "admin", and if we allow names from anywhere besides github we're going to need a name-collision-avoiding mechanism. Filed #132

redirect(`/${auth.user.name}`)
}
Loading