aboutsummaryrefslogtreecommitdiffstats
path: root/src/hooks/index.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-08-01 22:56:41 -0700
committerAdam Soltys <[email protected]>2022-08-01 22:56:41 -0700
commitc47a1a57c11e1a23ab00e382d79383360263ba62 (patch)
tree0cd09dac3ab292d7b80730f25fe9ab2e6c3e0fba /src/hooks/index.js
parent3294635775ecfdde539adcc38007418f3d5bf3f2 (diff)
downloadcoinos-ui-c47a1a57c11e1a23ab00e382d79383360263ba62.tar.gz
coinos-ui-c47a1a57c11e1a23ab00e382d79383360263ba62.zip
404 on invalid user
Diffstat (limited to 'src/hooks/index.js')
-rw-r--r--src/hooks/index.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/hooks/index.js b/src/hooks/index.js
index 6a9c8ec5..2284d88d 100644
--- a/src/hooks/index.js
+++ b/src/hooks/index.js
@@ -1,6 +1,10 @@
import cookie from 'cookie';
+import { get } from '$lib/utils';
+import { protectedRoutes } from '$lib/utils';
+
export async function handle({ event, resolve }) {
let {
+ params,
request: { headers }
} = event;
@@ -8,6 +12,11 @@ export async function handle({ event, resolve }) {
let { token } = cookies;
event.locals = { token };
+ if (protectedRoutes.find((p) => event.url.pathname.match(p))) {
+ let user = await get('/me', { accept: 'application/json', authorization: `Bearer ${token}` });
+ if (user.username !== params.username) throw new Error('user not found');
+ }
+
return resolve(event);
}