Conditional typing of locals on different routes #10919
Unanswered
einarpersson
asked this question in
Q&A
Replies: 1 comment
-
I could add a typeguard |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Consider an app that has three top level routes
/(public)/**
/user/**
/admin/**
Consider now that both user and admin has authentication, and that there are two distinct types of users. The user is added to locals as
or perhaps
I am checking for user etc in
hooks.server.ts
(and I am also using+page.server.ts
on each protected page).I would like to have it so that when I am in
/user/***
thelocals.user
has typeUser
and has typeAdmin
when in/admin/***
(or, have it as separate properties on locals as shown in the second example above).Is this possible somehow? Right now there is a lot of code duplication for me with typeguards everywhere...
Beta Was this translation helpful? Give feedback.
All reactions