File tree Expand file tree Collapse file tree 4 files changed +50
-3
lines changed
routes/(authenticated)/settings Expand file tree Collapse file tree 4 files changed +50
-3
lines changed Original file line number Diff line number Diff line change 22 import {logOutMutation , verifyQuery } from " $lib/backend" ;
33 import {useQueryClient } from " @tanstack/svelte-query" ;
44
5- const verify = verifyQuery ();
5+ const query = verifyQuery ();
66 const logOut = logOutMutation (useQueryClient ());
77
88 function handleLogOut(e : MouseEvent ) {
1919 <nav >
2020 <a href =" /" >🏠️</a >
2121 <a class =" plain" href =" /about" >About</a >
22- {#if $verify ?.data ?.is_authenticated }
22+ {#if $query ?.data ?.is_authenticated }
2323 <a href =" /settings" >Settings</a >
2424 <a href ="/log-out" on:click ={handleLogOut }>Log Out</a >
2525 {:else }
Original file line number Diff line number Diff line change @@ -48,8 +48,16 @@ export function logOutMutation(client: QueryClient) {
4848 } ) ;
4949}
5050
51+ export function currentUserQuery ( ) {
52+ return createQuery ( {
53+ queryFn : api ( ) . getCurrentUser ,
54+ queryKey : [ "current-user" ] ,
55+ } ) ;
56+ }
57+
5158export type Status = { status : string } ;
5259export type Verify = { is_authenticated : boolean } ;
60+ export type User = { user_id : string ; username : string ; }
5361
5462type SignUpArgs = { username : string ; email : string ; password : string ; } ;
5563type LogInArgs = { username_or_email : string ; password : string ; } ;
@@ -97,5 +105,12 @@ export function api(_fetch = fetch) {
97105 } ) ;
98106 return data as Status ;
99107 } ,
108+ getCurrentUser : async ( ) : Promise < User > => {
109+ const data = await handleFetch ( {
110+ url : `${ backend } /api/users/me` ,
111+ _fetch,
112+ } ) ;
113+ return data as User ;
114+ } ,
100115 } ;
101116}
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import {currentUserQuery } from " $lib/backend" ;
3+
4+ const query = currentUserQuery ();
5+ $ : user = $query ?.data ?? undefined ;
6+ </script >
7+
8+ <span class =" text-neutral-100" >Username:</span >
9+ {#if user }
10+ {user .username }
11+ {/if }
Original file line number Diff line number Diff line change 1+ <script >
2+ import Profile from " $lib/user/Profile.svelte" ;
3+ </script >
4+
15<svelte:head >
26 <title >Settings</title >
37 <meta name =" description" content =" User settings page" >
48</svelte:head >
59
6- <h1 >Settings</h1 >
10+ <main class =" max-w-7xl mx-auto p-4" >
11+ <h1 class =" text-5xl" >Settings</h1 >
12+ <div class =" flex flex-col gap-4 mt-4" >
13+ <section >
14+ <h2 >Profile</h2 >
15+ <Profile />
16+ </section >
17+ </div >
18+ </main >
19+
20+ <style lang =" postcss" >
21+ section {
22+ @apply mt-2;
23+ }
24+ section h2 {
25+ @apply text-2xl;
26+ }
27+ </style >
You can’t perform that action at this time.
0 commit comments