Skip to content

Commit 6340ddb

Browse files
fix: redirect user if they arent logged in (commaai#512)
Co-authored-by: Cameron Clough <cameronjclough@gmail.com>
1 parent 62d533c commit 6340ddb

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/pages/dashboard/Dashboard.tsx

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Component, JSXElement, VoidComponent } from 'solid-js'
33
import { Navigate, type RouteSectionProps, useLocation } from '@solidjs/router'
44
import clsx from 'clsx'
55

6+
import { isSignedIn } from '~/api/auth/client'
67
import { USERADMIN_URL } from '~/api/config'
78
import { getDevices } from '~/api/devices'
89
import { getProfile } from '~/api/profile'
@@ -51,25 +52,14 @@ const DashboardDrawer: VoidComponent<{ devices: Device[] }> = (props) => {
5152
<Suspense fallback={<div class="min-h-16 rounded-md skeleton-loader" />}>
5253
<div class="flex max-w-full items-center px-3 rounded-md outline outline-1 outline-outline-variant min-h-16">
5354
<div class="shrink-0 size-10 inline-flex items-center justify-center rounded-full bg-primary-container text-on-primary-container">
54-
<Icon name={!profile.loading && !profile.latest ? 'person_off' : 'person'} filled />
55+
<Icon name="person" filled />
5556
</div>
56-
<Show
57-
when={profile()}
58-
fallback={
59-
<>
60-
<div class="mx-3">Not signed in</div>
61-
<div class="grow" />
62-
<IconButton name="login" href="/login" />
63-
</>
64-
}
65-
>
66-
<div class="min-w-0 mx-3">
67-
<div class="truncate text-body-md text-on-surface">{profile()?.email}</div>
68-
<div class="truncate text-label-sm text-on-surface-variant">{profile()?.user_id}</div>
69-
</div>
70-
<div class="grow" />
71-
<IconButton name="logout" href="/logout" />
72-
</Show>
57+
<div class="min-w-0 mx-3">
58+
<div class="truncate text-body-md text-on-surface">{profile()?.email}</div>
59+
<div class="truncate text-label-sm text-on-surface-variant">{profile()?.user_id}</div>
60+
</div>
61+
<div class="grow" />
62+
<IconButton name="logout" href="/logout" />
7363
</div>
7464
</Suspense>
7565
</ButtonBase>
@@ -129,6 +119,9 @@ const Dashboard: Component<RouteSectionProps> = () => {
129119
return (
130120
<Drawer drawer={<DashboardDrawer devices={devices()} />}>
131121
<Switch fallback={<TopAppBar leading={<DrawerToggleButton />}>No device</TopAppBar>}>
122+
<Match when={!isSignedIn() || (!profile.loading && !profile.latest)}>
123+
<Navigate href="/login" />
124+
</Match>
132125
<Match when={urlState().dongleId === 'pair' || !!location.query.pair}>
133126
<PairActivity onPaired={refetch} />
134127
</Match>
@@ -159,9 +152,6 @@ const Dashboard: Component<RouteSectionProps> = () => {
159152
/>
160153
)}
161154
</Match>
162-
<Match when={!profile.loading && !profile.latest}>
163-
<Navigate href="/login" />
164-
</Match>
165155
<Match when={getDefaultDongleId()} keyed>
166156
{(defaultDongleId) => <Navigate href={`/${defaultDongleId}`} />}
167157
</Match>

0 commit comments

Comments
 (0)