"update user popover with dynamic user metadata loading and improved UI consistency,"
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { getUserMetaById } from '@/db/UserMetas/GetById';
|
||||
import { logger } from '@/lib/default-logger';
|
||||
import { pb } from '@/lib/pb';
|
||||
import type { User } from '@/types/user';
|
||||
|
||||
function generateToken(): string {
|
||||
@@ -8,7 +11,7 @@ function generateToken(): string {
|
||||
return Array.from(arr, (v) => v.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
|
||||
const user = {
|
||||
const user_xxx = {
|
||||
id: 'USR-000',
|
||||
avatar: '/assets/avatar.png',
|
||||
firstName: 'Sofia',
|
||||
@@ -54,17 +57,23 @@ class AuthClient {
|
||||
async signInWithPassword(params: SignInWithPasswordParams): Promise<{ error?: string }> {
|
||||
const { email, password } = params;
|
||||
|
||||
// Make API request
|
||||
try {
|
||||
// Make API request
|
||||
await pb.collection('users').authWithPassword(email, password);
|
||||
|
||||
// We do not handle the API, so we'll check if the credentials match with the hardcoded ones.
|
||||
if (email !== 'sofia@devias.io' || password !== 'Secret1') {
|
||||
// // We do not handle the API, so we'll check if the credentials match with the hardcoded ones.
|
||||
// if (email !== 'sofia@devias.io' || password !== 'Secret1') {
|
||||
// return { error: 'Invalid credentials' };
|
||||
// }
|
||||
// const token = generateToken();
|
||||
|
||||
localStorage.setItem('custom-auth-token', pb.authStore.token);
|
||||
|
||||
return {};
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return { error: 'Invalid credentials' };
|
||||
}
|
||||
|
||||
const token = generateToken();
|
||||
localStorage.setItem('custom-auth-token', token);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
async resetPassword(_: ResetPasswordParams): Promise<{ error?: string }> {
|
||||
@@ -79,16 +88,28 @@ class AuthClient {
|
||||
// Make API request
|
||||
|
||||
// We do not handle the API, so just check if we have a token in localStorage.
|
||||
const token = localStorage.getItem('custom-auth-token');
|
||||
// const token = localStorage.getItem('custom-auth-token');
|
||||
// if (!token) {
|
||||
// return { data: null };
|
||||
// }
|
||||
try {
|
||||
logger.debug(JSON.stringify(`getUser: ${pb.authStore.record?.id}`));
|
||||
//
|
||||
if (pb.authStore.record?.id !== undefined) {
|
||||
const userMeta = await getUserMetaById(pb.authStore.record?.id);
|
||||
logger.debug({ userMeta });
|
||||
return { data: userMeta as unknown as User };
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
return { data: null };
|
||||
} catch (error) {
|
||||
return { error: 'sorry cannot get user meta' };
|
||||
}
|
||||
|
||||
return { data: user };
|
||||
}
|
||||
|
||||
async signOut(): Promise<{ error?: string }> {
|
||||
pb.authStore.clear();
|
||||
|
||||
localStorage.removeItem('custom-auth-token');
|
||||
|
||||
return {};
|
||||
|
Reference in New Issue
Block a user