BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/better-auth-ui/auth-redirect

Auth Redirect

better-auth-ui/auth-redirect
FreeComponent

A session-aware redirect view that safely continues authenticated users to a same-origin target or sends them through sign in first.

Live preview

live · rendered by the registry
Rendered by better-auth-ui on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://better-auth-ui.com/r/auth-redirect.json

Source

src/components/auth/auth-redirect.tsxbetter-auth-ui.com/r/auth-redirect.json
1"use client"
2
3import { getAuthRedirectAction } from "@better-auth-ui/core"
4import { useAuth, useSession } from "@better-auth-ui/react"
5import { useEffect, useRef } from "react"
6import { Spinner } from "@/components/ui/spinner"
7import { cn } from "@/lib/utils"
8
9export type AuthRedirectProps = {
10 className?: string
11}
12
13/**
14 * Redirects authenticated users to a validated same-origin target.
15 *
16 * Signed-out users are sent through the sign-in view first. The redirect view
17 * is preserved as the post-authentication destination so API callbacks receive
18 * a full-page request after the session is established.
19 *
20 * @param className - Optional additional class names applied to the spinner
21 * @returns The centered spinner shown while the session and redirect resolve
22 */
23export function AuthRedirect({ className }: AuthRedirectProps) {
24 const { authClient, basePaths, viewPaths } = useAuth()
25 const { data: session, isPending } = useSession(authClient)
26 const hasRedirected = useRef(false)
27
28 useEffect(() => {
29 if (isPending || hasRedirected.current) return
30 hasRedirected.current = true
31
32 const action = getAuthRedirectAction(
33 new URL(window.location.href),
34 Boolean(session),
35 `${basePaths.auth}/${viewPaths.auth.signIn}`
36 )
37
38 window.location.replace(action.to)
39 }, [basePaths.auth, isPending, session, viewPaths.auth.signIn])
40
41 return <Spinner className={cn("mx-auto my-auto", className)} />
42}

What it pulls in

npm packages

  • @better-auth-ui/react@latest
  • @better-auth-ui/core@latest
  • better-auth

Other registry items

  • spinner

Files it writes

  • src/components/auth/auth-redirect.tsx

Facts

Registry
better-auth-ui
Type
registry:component
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-02
Last confirmed
today

Go to the source

Docs on better-auth-ui better-auth-ui.com better-auth-ui/better-auth-ui on GitHub Raw registry item This item as JSON

More from better-auth-ui

All 49 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Account Settingsaccount-settingsbetter-auth-uiComponentsFree2 deps
Active Sessionsactive-sessionsbetter-auth-uiComponentsFree5 deps · 2 files
Additional Fieldadditional-fieldbetter-auth-uiComponentsFree5 deps
Adminadminbetter-auth-uiComponentsFree4 deps · 3 files
Anonymousanonymousbetter-auth-uiComponentsFree4 deps · 3 files
API Keyapi-keybetter-auth-uiComponentsFree4 deps · 10 files
Authauthbetter-auth-uiComponentsFree2 deps
Auth Providerauth-providerbetter-auth-uiComponentsFree4 deps · 2 files
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex