@@ -8,26 +8,38 @@ import type { ProfileData } from '@open-source-consent/ui';
88 * This framework does not provide auth or user management.
99 */
1010
11+ export type BasicUserInfo = {
12+ id : string ;
13+ name : string ;
14+ } ;
15+
1116const USER_ID_STORAGE_KEY = 'currentUserId' ;
17+ const USER_NAME_STORAGE_KEY = 'currentUserName' ;
18+
19+ function getCurrentUserName ( ) : string | null {
20+ return localStorage . getItem ( USER_NAME_STORAGE_KEY ) ;
21+ }
1222
1323export function getCurrentUserId ( ) : string | null {
1424 return localStorage . getItem ( USER_ID_STORAGE_KEY ) ;
1525}
1626
17- export function login ( userId : string ) : void {
18- localStorage . setItem ( USER_ID_STORAGE_KEY , userId ) ;
27+ export function login ( user : BasicUserInfo ) : void {
28+ localStorage . setItem ( USER_ID_STORAGE_KEY , user . id ) ;
29+ localStorage . setItem ( USER_NAME_STORAGE_KEY , user . name ) ;
1930}
2031
2132export function logout ( ) : void {
2233 localStorage . removeItem ( USER_ID_STORAGE_KEY ) ;
34+ localStorage . removeItem ( USER_NAME_STORAGE_KEY ) ;
2335}
2436
2537export async function fetchUserProfile (
2638 userId : string ,
2739) : Promise < ProfileData | null > {
2840 return {
2941 id : userId ,
30- name : `${ userId } ` ,
42+ name : getCurrentUserName ( ) || `${ userId } ` ,
3143 email : `${ userId . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '-' ) } @example.com` ,
3244 role : { id : 'self' , label : 'Myself' } ,
3345 consents : [ ] , // These are fetched from the API
0 commit comments