File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
src/routes/_authenticated Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ cp .env.example .env
25
25
26
26
## Running the Application
27
27
28
- __ Note : Docker is required to run this starter __
28
+ ** Note : Docker is required to run this starter **
29
29
30
30
To run this application:
31
31
Original file line number Diff line number Diff line change 1
- import { createFileRoute , useNavigate } from "@tanstack/react-router"
1
+ import { createFileRoute , redirect , useNavigate } from "@tanstack/react-router"
2
2
import { useLiveQuery } from "@tanstack/react-db"
3
3
import { useEffect } from "react"
4
4
import { projectCollection , todoCollection } from "@/lib/collections"
5
+ import { authClient } from "@/lib/auth-client"
5
6
6
7
export const Route = createFileRoute ( `/_authenticated/` ) ( {
7
8
component : IndexRedirect ,
8
9
ssr : false ,
10
+ beforeLoad : async ( ) => {
11
+ const res = await authClient . getSession ( )
12
+ if ( ! res . data ?. session ) {
13
+ throw redirect ( {
14
+ to : `/login` ,
15
+ search : {
16
+ // Use the current location to power a redirect after login
17
+ // (Do not use `router.state.resolvedLocation` as it can
18
+ // potentially lag behind the actual current location)
19
+ redirect : location . href ,
20
+ } ,
21
+ } )
22
+ }
23
+ } ,
9
24
loader : async ( ) => {
10
- const timeout = setTimeout ( ( ) => {
11
- window . location . href = `/login`
12
- } , 500 )
13
25
await projectCollection . preload ( )
14
26
await todoCollection . preload ( )
15
- clearTimeout ( timeout )
16
27
17
28
return null
18
29
} ,
You can’t perform that action at this time.
0 commit comments