fix(codebase): 🐛 resolve registration and login issues in auth provider and sso client

This commit is contained in:
Lilith 2026-01-10 06:49:38 -08:00
parent 89b97c0832
commit 5a8ff4cee8
4 changed files with 76 additions and 0 deletions

View file

@ -503,4 +503,32 @@ export class SSOClient {
return result;
}
async registerWithCredentials(
email: string,
username: string,
password: string,
role?: 'user' | 'provider' | 'client'
): Promise<LoginResult> {
const response = await fetch(`${this.config.ssoUrl}/auth/register`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, username, password, role }),
});
const result: LoginResult = await response.json();
if (!response.ok) {
throw new Error((result as { message?: string }).message || 'Registration failed');
}
if (result.user && result.sessionId) {
this.setToken(result.sessionId);
this.currentUser = result.user;
this.authenticated = true;
this.config.onAuthChange?.(true, result.user);
}
return result;
}
}

View file

@ -7,6 +7,7 @@ import type {
AuthState,
LoginCredentials,
RegisterData,
DirectRegisterData,
User,
} from './types';

View file

@ -26,12 +26,21 @@ export interface RegisterData {
email?: string;
username?: string;
password?: string;
/** User role for marketplace registration */
role?: UserRole;
/** User types for registration (business identity) */
userTypes?: UserType[];
/** Primary user type */
primaryUserType?: UserType;
}
export interface DirectRegisterData {
email: string;
username: string;
password: string;
role?: UserRole;
}
export interface AuthResponse {
user: User;
accessToken: string;
@ -46,8 +55,14 @@ export interface AuthState {
}
export interface AuthContextValue extends AuthState {
/** Opens SSO popup for login */
login: (credentials: LoginCredentials) => Promise<void>;
/** Opens SSO popup for registration */
register: (data: RegisterData) => Promise<void>;
/** Direct login with email/password (no popup) */
loginWithCredentials: (email: string, password: string) => Promise<void>;
/** Direct registration (no popup) */
registerWithCredentials: (data: DirectRegisterData) => Promise<void>;
logout: () => Promise<void>;
refreshAuth: () => Promise<void>;
}

View file

@ -22,6 +22,13 @@ import {
SystemServiceUnhealthyPayload,
SystemAlertTriggeredPayload,
SystemAlertResolvedPayload,
// Service discovery events
ServiceRegisteredPayload,
ServiceDeregisteredPayload,
ServiceHealthChangedPayload,
ServiceDrainingPayload,
ServiceScaledPayload,
ServiceMetadataUpdatedPayload,
} from '@lilith/domain-events'
import { BaseDomainEventsProcessor } from '@lilith/domain-events/processors'
@ -73,6 +80,31 @@ export class SystemEventsProcessor extends BaseDomainEventsProcessor {
await this.handleAlertResolved(event as BaseDomainEvent<SystemAlertResolvedPayload>)
break
// Service discovery events
case DomainEventType.SERVICE_REGISTERED:
await this.handleServiceRegistered(event as BaseDomainEvent<ServiceRegisteredPayload>)
break
case DomainEventType.SERVICE_DEREGISTERED:
await this.handleServiceDeregistered(event as BaseDomainEvent<ServiceDeregisteredPayload>)
break
case DomainEventType.SERVICE_HEALTH_CHANGED:
await this.handleServiceHealthChanged(event as BaseDomainEvent<ServiceHealthChangedPayload>)
break
case DomainEventType.SERVICE_DRAINING:
await this.handleServiceDraining(event as BaseDomainEvent<ServiceDrainingPayload>)
break
case DomainEventType.SERVICE_SCALED:
await this.handleServiceScaled(event as BaseDomainEvent<ServiceScaledPayload>)
break
case DomainEventType.SERVICE_METADATA_UPDATED:
await this.handleServiceMetadataUpdated(event as BaseDomainEvent<ServiceMetadataUpdatedPayload>)
break
default:
// Not a system event - ignore silently
return