Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit 234c198

Browse files
committed
refactor: use search param instead of path param when linking a device (#414)
Closes FRONT-545
1 parent 6e47ab9 commit 234c198

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

apps/hub/src/routeTree.gen.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ import { Route as AuthenticatedBillingImport } from './routes/_authenticated/bil
1717
import { Route as AuthenticatedLayoutImport } from './routes/_authenticated/_layout'
1818
import { Route as AuthenticatedLayoutIndexImport } from './routes/_authenticated/_layout/index'
1919
import { Route as AuthenticatedInviteInviteCodeImport } from './routes/_authenticated/invite.$inviteCode'
20+
import { Route as AuthenticatedDevicesLinkImport } from './routes/_authenticated/devices.link'
2021
import { Route as AuthenticatedAccessTokenTokenImport } from './routes/_authenticated/access-token.$token'
2122
import { Route as AuthenticatedLayoutMyProfileImport } from './routes/_authenticated/_layout/my-profile'
2223
import { Route as AuthenticatedLayoutMyProfileIndexImport } from './routes/_authenticated/_layout/my-profile/index'
23-
import { Route as AuthenticatedDevicesLinkTokenImport } from './routes/_authenticated/devices.link.$token'
24+
import { Route as AuthenticatedDevicesLinkTokenImport } from './routes/_authenticated/devices.link_.$token'
2425
import { Route as AuthenticatedLayoutTeamsGroupIdImport } from './routes/_authenticated/_layout/teams/$groupId'
2526
import { Route as AuthenticatedLayoutProjectsProjectIdImport } from './routes/_authenticated/_layout/projects/$projectId'
2627
import { Route as AuthenticatedLayoutMyProfileFeaturesImport } from './routes/_authenticated/_layout/my-profile/features'
@@ -89,6 +90,11 @@ const AuthenticatedInviteInviteCodeRoute =
8990
getParentRoute: () => AuthenticatedRoute,
9091
} as any)
9192

93+
const AuthenticatedDevicesLinkRoute = AuthenticatedDevicesLinkImport.update({
94+
path: '/devices/link',
95+
getParentRoute: () => AuthenticatedRoute,
96+
} as any)
97+
9298
const AuthenticatedAccessTokenTokenRoute =
9399
AuthenticatedAccessTokenTokenImport.update({
94100
path: '/access-token/$token',
@@ -414,6 +420,13 @@ declare module '@tanstack/react-router' {
414420
preLoaderRoute: typeof AuthenticatedAccessTokenTokenImport
415421
parentRoute: typeof AuthenticatedImport
416422
}
423+
'/_authenticated/devices/link': {
424+
id: '/_authenticated/devices/link'
425+
path: '/devices/link'
426+
fullPath: '/devices/link'
427+
preLoaderRoute: typeof AuthenticatedDevicesLinkImport
428+
parentRoute: typeof AuthenticatedImport
429+
}
417430
'/_authenticated/invite/$inviteCode': {
418431
id: '/_authenticated/invite/$inviteCode'
419432
path: '/invite/$inviteCode'
@@ -915,6 +928,7 @@ interface AuthenticatedRouteChildren {
915928
AuthenticatedLayoutRoute: typeof AuthenticatedLayoutRouteWithChildren
916929
AuthenticatedBillingRoute: typeof AuthenticatedBillingRoute
917930
AuthenticatedAccessTokenTokenRoute: typeof AuthenticatedAccessTokenTokenRoute
931+
AuthenticatedDevicesLinkRoute: typeof AuthenticatedDevicesLinkRoute
918932
AuthenticatedInviteInviteCodeRoute: typeof AuthenticatedInviteInviteCodeRoute
919933
AuthenticatedDevicesLinkTokenRoute: typeof AuthenticatedDevicesLinkTokenRoute
920934
}
@@ -923,6 +937,7 @@ const AuthenticatedRouteChildren: AuthenticatedRouteChildren = {
923937
AuthenticatedLayoutRoute: AuthenticatedLayoutRouteWithChildren,
924938
AuthenticatedBillingRoute: AuthenticatedBillingRoute,
925939
AuthenticatedAccessTokenTokenRoute: AuthenticatedAccessTokenTokenRoute,
940+
AuthenticatedDevicesLinkRoute: AuthenticatedDevicesLinkRoute,
926941
AuthenticatedInviteInviteCodeRoute: AuthenticatedInviteInviteCodeRoute,
927942
AuthenticatedDevicesLinkTokenRoute: AuthenticatedDevicesLinkTokenRoute,
928943
}
@@ -937,6 +952,7 @@ export interface FileRoutesByFullPath {
937952
'/billing': typeof AuthenticatedBillingRoute
938953
'/my-profile': typeof AuthenticatedLayoutMyProfileRouteWithChildren
939954
'/access-token/$token': typeof AuthenticatedAccessTokenTokenRoute
955+
'/devices/link': typeof AuthenticatedDevicesLinkRoute
940956
'/invite/$inviteCode': typeof AuthenticatedInviteInviteCodeRoute
941957
'/': typeof AuthenticatedLayoutIndexRoute
942958
'/games/$': typeof AuthenticatedLayoutGamesSplatRoute
@@ -982,6 +998,7 @@ export interface FileRoutesByTo {
982998
'/login': typeof LoginRoute
983999
'/billing': typeof AuthenticatedBillingRoute
9841000
'/access-token/$token': typeof AuthenticatedAccessTokenTokenRoute
1001+
'/devices/link': typeof AuthenticatedDevicesLinkRoute
9851002
'/invite/$inviteCode': typeof AuthenticatedInviteInviteCodeRoute
9861003
'/': typeof AuthenticatedLayoutIndexRoute
9871004
'/games/$': typeof AuthenticatedLayoutGamesSplatRoute
@@ -1023,6 +1040,7 @@ export interface FileRoutesById {
10231040
'/_authenticated/billing': typeof AuthenticatedBillingRoute
10241041
'/_authenticated/_layout/my-profile': typeof AuthenticatedLayoutMyProfileRouteWithChildren
10251042
'/_authenticated/access-token/$token': typeof AuthenticatedAccessTokenTokenRoute
1043+
'/_authenticated/devices/link': typeof AuthenticatedDevicesLinkRoute
10261044
'/_authenticated/invite/$inviteCode': typeof AuthenticatedInviteInviteCodeRoute
10271045
'/_authenticated/_layout/': typeof AuthenticatedLayoutIndexRoute
10281046
'/_authenticated/_layout/games/$': typeof AuthenticatedLayoutGamesSplatRoute
@@ -1071,6 +1089,7 @@ export interface FileRouteTypes {
10711089
| '/billing'
10721090
| '/my-profile'
10731091
| '/access-token/$token'
1092+
| '/devices/link'
10741093
| '/invite/$inviteCode'
10751094
| '/'
10761095
| '/games/$'
@@ -1115,6 +1134,7 @@ export interface FileRouteTypes {
11151134
| '/login'
11161135
| '/billing'
11171136
| '/access-token/$token'
1137+
| '/devices/link'
11181138
| '/invite/$inviteCode'
11191139
| '/'
11201140
| '/games/$'
@@ -1154,6 +1174,7 @@ export interface FileRouteTypes {
11541174
| '/_authenticated/billing'
11551175
| '/_authenticated/_layout/my-profile'
11561176
| '/_authenticated/access-token/$token'
1177+
| '/_authenticated/devices/link'
11571178
| '/_authenticated/invite/$inviteCode'
11581179
| '/_authenticated/_layout/'
11591180
| '/_authenticated/_layout/games/$'
@@ -1227,6 +1248,7 @@ export const routeTree = rootRoute
12271248
"/_authenticated/_layout",
12281249
"/_authenticated/billing",
12291250
"/_authenticated/access-token/$token",
1251+
"/_authenticated/devices/link",
12301252
"/_authenticated/invite/$inviteCode",
12311253
"/_authenticated/devices/link/$token"
12321254
]
@@ -1261,6 +1283,10 @@ export const routeTree = rootRoute
12611283
"filePath": "_authenticated/access-token.$token.tsx",
12621284
"parent": "/_authenticated"
12631285
},
1286+
"/_authenticated/devices/link": {
1287+
"filePath": "_authenticated/devices.link.tsx",
1288+
"parent": "/_authenticated"
1289+
},
12641290
"/_authenticated/invite/$inviteCode": {
12651291
"filePath": "_authenticated/invite.$inviteCode.tsx",
12661292
"parent": "/_authenticated"
@@ -1300,7 +1326,7 @@ export const routeTree = rootRoute
13001326
]
13011327
},
13021328
"/_authenticated/devices/link/$token": {
1303-
"filePath": "_authenticated/devices.link.$token.tsx",
1329+
"filePath": "_authenticated/devices.link_.$token.tsx",
13041330
"parent": "/_authenticated"
13051331
},
13061332
"/_authenticated/_layout/my-profile/": {

apps/hub/src/routes/_authenticated/devices.link.$token.tsx renamed to apps/hub/src/routes/_authenticated/devices.link.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ import {
1717
Text,
1818
} from "@rivet-gg/components";
1919
import { Link, createFileRoute, notFound } from "@tanstack/react-router";
20+
import { zodSearchValidator } from "@tanstack/router-zod-adapter";
21+
import { z } from "zod";
22+
2023
function DeviceLinkTokenRoute() {
21-
const { token } = Route.useParams();
24+
const { token } = Route.useSearch();
2225

2326
const { mutateAsync, isSuccess } = useCompleteDeviceLinkMutation();
2427

@@ -80,9 +83,14 @@ function DeviceLinkTokenRoute() {
8083
);
8184
}
8285

83-
export const Route = createFileRoute("/_authenticated/devices/link/$token")({
86+
export const searchSchema = z.object({
87+
token: z.string(),
88+
});
89+
90+
export const Route = createFileRoute("/_authenticated/devices/link")({
91+
validateSearch: zodSearchValidator(searchSchema),
8492
component: DeviceLinkTokenRoute,
85-
loader: async ({ params: { token } }) => {
93+
beforeLoad: async ({ search: { token } }) => {
8694
try {
8795
const response = await queryClient.fetchQuery(
8896
deviceLinkTokenQueryOptions(token),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { createFileRoute, redirect } from "@tanstack/react-router";
2+
3+
export const Route = createFileRoute("/_authenticated/devices/link/$token")({
4+
beforeLoad: async ({ params: { token } }) => {
5+
throw redirect({
6+
to: "/devices/link",
7+
search: { token },
8+
});
9+
},
10+
});

0 commit comments

Comments
 (0)