Skip to content

Commit 26551cf

Browse files
committed
feat: build a real UCAuth
Do not use FAKE_USER_REGULAR anymore. Build a proper UCAuth. For the organizationId, generate one using CryptoManager. For the firstname, capitalize the first part of the email address (before arobase) THIS IS A NIGHTMARE. LOOKS LIKE SOMEONE WHO LIED ON THEIR RESUME, TRYING TO SOLVE A SIMPLE PROBLEM DURING AN INTERVIEW.
1 parent 293aa85 commit 26551cf

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

examples/apps/Auth/src/ucds/SignUpServerMain.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { inject, injectable } from 'inversify';
22

33
import {
4-
FAKE_USER_REGULAR,
5-
type JWTManager,
4+
type CryptoManager,
65
type UCAuth,
76
type UCMain,
87
type UCMainInput,
@@ -11,6 +10,7 @@ import {
1110
UCOutputBuilder,
1211
} from '../../../../../dist/esm/index.js';
1312
import type { SignUpInput, SignUpOPI0 } from './SignUpUCD.js';
13+
import { UCAuth } from '../uc/auth/consts.js';
1414

1515
@injectable()
1616
export class SignUpServerMain implements UCMain<SignUpInput, SignUpOPI0> {
@@ -19,25 +19,50 @@ export class SignUpServerMain implements UCMain<SignUpInput, SignUpOPI0> {
1919
private jwtManager: JWTManager,
2020
@inject('UCManager')
2121
private ucManager: UCManager,
22+
@inject('CryptoManager')
23+
private cryptoManager: CryptoManager,
2224
) {}
2325

2426
public async exec({
2527
uc,
2628
}: UCMainInput<SignUpInput, SignUpOPI0>): Promise<UCOutput<SignUpOPI0>> {
29+
const email = uc.reqVal0('email');
30+
const password = uc.reqVal0('password');
31+
2732
// DO NOT USE THIS IN PRODUCTION !!!
2833
// TODO: In production, validate email format and password strength
29-
// TODO: Check if email already exists in database
34+
// TODO: Check if email already exists in database
3035
// TODO: Hash password before storing
3136

3237
/// Persist the use case first to get aggregateId
3338
const { aggregateId } = await this.ucManager.persist(uc);
3439

3540
// Always create a regular user for signup (no role selection)
41+
const auth = FAKE_USER_REGULAR;
42+
43+
const jwt = await this.jwtManager.encode(auth);
44+
45+
return new UCOutputBuilder<SignUpOPI0>()
46+
.add({
47+
id: aggregateId,
48+
jwt
49+
})
50+
.get();
51+
}
52+
}
53+
54+
// Hash password using CryptoManager
55+
const hashedPassword = await this.cryptoManager.hash(
56+
password,
57+
'sha256',
58+
);
59+
60+
// Create auth object with proper structure
3661
const auth: UCAuth = {
37-
...FAKE_USER_REGULAR,
62+
organizationId,
3863
user: {
39-
...FAKE_USER_REGULAR.user,
4064
id: aggregateId,
65+
name,
4166
},
4267
};
4368

0 commit comments

Comments
 (0)