Something went wrong. Try again.
A social knowledge tool for research trails, built on ATProto semble.so
research-tool social-network tools-for-thought atproto
Something went wrong. Try again.
TypeScript
at development
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import { Result, err, ok } from 'src/shared/core/Result';import { IUserRepository } from '../../domain/repositories/IUserRepository';import { IUserAuthenticationService, AuthenticationResult,} from '../../domain/services/IUserAuthenticationService';import { DID } from '../../domain/value-objects/DID';import { Handle } from '../../domain/value-objects/Handle';import { User } from '../../domain/User';
export class UserAuthenticationService implements IUserAuthenticationService { constructor(private userRepository: IUserRepository) {}
async validateUserCredentials( did: DID, handle?: Handle, ): Promise<Result<AuthenticationResult>> { try { // Try to find existing user const userResult = await this.userRepository.findByDID(did);
if (userResult.isErr()) { return err(userResult.error); }
const existingUser = userResult.value;
// If user exists, update handle if provided if (existingUser) { if ( handle && (!existingUser.handle || existingUser.handle.value !== handle.value) ) { existingUser.updateHandle(handle); }
return ok({ user: existingUser, isNewUser: false, }); }
// Create new user const newUserResult = User.createNew(did, handle);
if (newUserResult.isErr()) { return err(newUserResult.error); }
return ok({ user: newUserResult.value, isNewUser: true, }); } catch (error: any) { return err(error); } }}