Skip to content

Commit 293aa85

Browse files
committed
feat: set role to regular by default
Now remove the usage of the default roles, remove the role input field and set the role to "regular" by default when a user signs up.
1 parent f5622de commit 293aa85

File tree

4 files changed

+26
-60
lines changed

4 files changed

+26
-60
lines changed

examples/apps/Auth/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ sequenceDiagram
111111
|---|---|---|---|
112112
|1|`email`|Email|`string`|
113113
|2|`password`|Password|`string`|
114-
|3|`role`|Role|`Role`|
115114

116115
#### Output (O)
117116

@@ -131,13 +130,13 @@ None
131130
```mermaid
132131
sequenceDiagram
133132
actor User
134-
User->>+Client: ✏️ Fill<br/>email: string<br/>password: string<br/>role: Role
133+
User->>+Client: ✏️ Fill<br/>email: string<br/>password: string
135134
User->>Client: ↩️ Submit
136135
Client->>Client: 🔐 Check policy "Anonymous"
137136
break when any validation fails
138137
Client-->User: show failure
139138
end
140-
Client->>+Server: 📤 Send<br/>email: string<br/>password: string<br/>role: Role
139+
Client->>+Server: 📤 Send<br/>email: string<br/>password: string
141140
Server->>Server: 🔐 Check policy "Anonymous"
142141
break when any validation fails
143142
Server-->User: show failure
@@ -153,4 +152,4 @@ sequenceDiagram
153152
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
154153
|1|/src/ucds/SignInUCD.ts|SignInUCD|SignIn|Create||right-to-bracket||||../../../../../dist/esm/index.js<br>../lib/TRole.js<br>../manifest.js<br>./SignInServerMain.js|SignInInput|role: UCInputFieldValue&#60;Role&#62;|SignInOPI0|jwt: JWT<br>id: UUID|||Anonymous|Anonymous|
155154
|2|/src/ucds/SignOutUCD.ts|SignOutUCD|SignOut|Delete||circle-xmark||true||../../../../../dist/esm/index.js<br>../manifest.js|||||||Authenticated|Authenticated|
156-
|3|/src/ucds/SignUpUCD.ts|SignUpUCD|SignUp|Create||user-plus||||../../../../../dist/esm/index.js<br>../lib/TRole.js<br>../manifest.js<br>./SignUpServerMain.js|SignUpInput|email: UCInputFieldValue&#60;string&#62;<br>password: UCInputFieldValue&#60;string&#62;<br>role: UCInputFieldValue&#60;Role&#62;|SignUpOPI0|jwt: JWT<br>id: UUID|||Anonymous|Anonymous|
155+
|3|/src/ucds/SignUpUCD.ts|SignUpUCD|SignUp|Create||user-plus||||../../../../../dist/esm/index.js<br>../manifest.js<br>./SignUpServerMain.js|SignUpInput|email: UCInputFieldValue&#60;string&#62;<br>password: UCInputFieldValue&#60;string&#62;|SignUpOPI0|jwt: JWT<br>id: UUID|||Anonymous|Anonymous|

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

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

33
import {
4-
FAKE_USER_ADMIN,
54
FAKE_USER_REGULAR,
65
type JWTManager,
76
type UCAuth,
@@ -25,8 +24,6 @@ export class SignUpServerMain implements UCMain<SignUpInput, SignUpOPI0> {
2524
public async exec({
2625
uc,
2726
}: UCMainInput<SignUpInput, SignUpOPI0>): Promise<UCOutput<SignUpOPI0>> {
28-
const role = uc.reqVal0('role');
29-
3027
// DO NOT USE THIS IN PRODUCTION !!!
3128
// TODO: In production, validate email format and password strength
3229
// TODO: Check if email already exists in database
@@ -35,31 +32,15 @@ export class SignUpServerMain implements UCMain<SignUpInput, SignUpOPI0> {
3532
/// Persist the use case first to get aggregateId
3633
const { aggregateId } = await this.ucManager.persist(uc);
3734

38-
// For this demo, we'll just create a JWT based on role
39-
// but use the aggregateId as the user ID
40-
let auth!: UCAuth;
41-
switch (role) {
42-
case 'admin':
43-
auth = {
44-
...FAKE_USER_ADMIN,
45-
user: {
46-
...FAKE_USER_ADMIN.user,
47-
id: aggregateId,
48-
},
49-
};
50-
break;
51-
case 'regular':
52-
auth = {
53-
...FAKE_USER_REGULAR,
54-
user: {
55-
...FAKE_USER_REGULAR.user,
56-
id: aggregateId,
57-
},
58-
};
59-
break;
60-
default:
61-
role satisfies never;
62-
}
35+
// Always create a regular user for signup (no role selection)
36+
const auth: UCAuth = {
37+
...FAKE_USER_REGULAR,
38+
user: {
39+
...FAKE_USER_REGULAR.user,
40+
id: aggregateId,
41+
},
42+
};
43+
6344
const jwt = await this.jwtManager.encode(auth);
6445

6546
return new UCOutputBuilder<SignUpOPI0>()

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ import {
1111
type UCOPIBase,
1212
UCOutputSideEffectType,
1313
} from '../../../../../dist/esm/index.js';
14-
import { type Role, TRole } from '../lib/TRole.js';
1514
import { Manifest } from '../manifest.js';
1615
import { SignUpServerMain } from './SignUpServerMain.js';
1716

1817
export interface SignUpInput extends UCInput {
1918
email: UCInputFieldValue<string>;
2019
password: UCInputFieldValue<string>;
21-
role: UCInputFieldValue<Role>;
2220
}
2321

2422
export interface SignUpOPI0 extends UCOPIBase {
@@ -35,9 +33,6 @@ export const SignUpUCD: UCDef<SignUpInput, SignUpOPI0> = {
3533
password: {
3634
type: new TPassword(),
3735
},
38-
role: {
39-
type: new TRole(),
40-
},
4136
},
4237
},
4338
o: {

examples/apps/Auth/test/__snapshots__/App.test.ts.snap

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ exports[`Run > Use Cases > 'SignOut' > should execute with auth 'REGULAR' and in
454454
}
455455
`;
456456

457-
exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ADMIN' and input 'ALL_WITH_EXAMPLES' > hash = 55d051ec38edd0f2829741d6d093cab16fd3509b94318bf3d5faef96ecfa987a 1`] = `
457+
exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ADMIN' and input 'ALL_WITH_EXAMPLES' > hash = 5dbf39a3f94274b5cc62c26fc405c32cb434cfc3abcea2794c663aee33b45d7c 1`] = `
458458
{
459459
"out": {
460460
"args": {
@@ -474,12 +474,11 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ADMIN' and input
474474
"inputFillerName": "ALL_WITH_EXAMPLES",
475475
},
476476
"err": [ForbiddenError: Forbidden],
477-
"hash": "55d051ec38edd0f2829741d6d093cab16fd3509b94318bf3d5faef96ecfa987a",
477+
"hash": "5dbf39a3f94274b5cc62c26fc405c32cb434cfc3abcea2794c663aee33b45d7c",
478478
"io": {
479479
"i": {
480480
"email": "dexter@caramail.com",
481481
"password": "fmUUNWXazWH4",
482-
"role": "admin",
483482
},
484483
"o": null,
485484
},
@@ -488,7 +487,7 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ADMIN' and input
488487
}
489488
`;
490489

491-
exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ADMIN' and input 'ONLY_MANDATORY_WITH_EXAMPLES' > hash = 315316ff2eaff314d732d78bd54904e755d49d5d44b000834158f2b22cb01adf 1`] = `
490+
exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ADMIN' and input 'ONLY_MANDATORY_WITH_EXAMPLES' > hash = 90d904a51f4c0248cd4a28f91fdd571756ee60719aacefc3223c3b8df86b4a77 1`] = `
492491
{
493492
"out": {
494493
"args": {
@@ -508,12 +507,11 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ADMIN' and input
508507
"inputFillerName": "ONLY_MANDATORY_WITH_EXAMPLES",
509508
},
510509
"err": [ForbiddenError: Forbidden],
511-
"hash": "315316ff2eaff314d732d78bd54904e755d49d5d44b000834158f2b22cb01adf",
510+
"hash": "90d904a51f4c0248cd4a28f91fdd571756ee60719aacefc3223c3b8df86b4a77",
512511
"io": {
513512
"i": {
514513
"email": "dexter@caramail.com",
515514
"password": "fmUUNWXazWH4",
516-
"role": "admin",
517515
},
518516
"o": null,
519517
},
@@ -547,7 +545,6 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ADMIN' and input
547545
"i": {
548546
"email": undefined,
549547
"password": undefined,
550-
"role": undefined,
551548
},
552549
"o": null,
553550
},
@@ -556,7 +553,7 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ADMIN' and input
556553
}
557554
`;
558555

559-
exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ANONYMOUS' and input 'ALL_WITH_EXAMPLES' > hash = 4e8951fd142064c3eb53bdd57a798fe5ebf2f57cc39cb192abd8001b1cd40c06 1`] = `
556+
exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ANONYMOUS' and input 'ALL_WITH_EXAMPLES' > hash = a9b91b0adfc04784ac4a628471106e5759b8a7bef8e2dbb888f3027b6a7697ef 1`] = `
560557
{
561558
"out": {
562559
"args": {
@@ -566,20 +563,19 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ANONYMOUS' and i
566563
"inputFillerName": "ALL_WITH_EXAMPLES",
567564
},
568565
"err": null,
569-
"hash": "4e8951fd142064c3eb53bdd57a798fe5ebf2f57cc39cb192abd8001b1cd40c06",
566+
"hash": "a9b91b0adfc04784ac4a628471106e5759b8a7bef8e2dbb888f3027b6a7697ef",
570567
"io": {
571568
"i": {
572569
"email": "dexter@caramail.com",
573570
"password": "fmUUNWXazWH4",
574-
"role": "admin",
575571
},
576572
"o": {
577573
"parts": {
578574
"_0": {
579575
"items": [
580576
{
581577
"id": "356a192b-7913-404c-9457-4d18c28d46e6",
582-
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcmdhbml6YXRpb24iOnsiaWQiOiJkZDk2NzBlNy0xZGQ1LTQxNTUtODVjMi0zMzU3MTQ3OTlmZjcifSwicm9sZSI6ImFkbWluIiwidXNlciI6eyJmaXJzdG5hbWUiOiJEZXh0ZXIiLCJpZCI6IjM1NmExOTJiLTc5MTMtNDA0Yy05NDU3LTRkMThjMjhkNDZlNiIsImluaXRpYWxzIjoiRE0ifSwiYXVkIjoibGlibW9kdWxvciIsImV4cCI6MTc2ODA1NDY4NCwiaXNzIjoibGlibW9kdWxvciIsImlhdCI6MTc2ODA1MTA4NH0.50t-rDF2Olqd-cJOTuFSvLtw1wUHVoWEj_3PNjmTfxw",
578+
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcmdhbml6YXRpb24iOnsiaWQiOiJkZDk2NzBlNy0xZGQ1LTQxNTUtODVjMi0zMzU3MTQ3OTlmZjcifSwicm9sZSI6InJlZ3VsYXIiLCJ1c2VyIjp7ImZpcnN0bmFtZSI6IkRleHRlciIsImlkIjoiMzU2YTE5MmItNzkxMy00MDRjLTk0NTctNGQxOGMyOGQ0NmU2IiwiaW5pdGlhbHMiOiJETSJ9LCJhdWQiOiJsaWJtb2R1bG9yIiwiZXhwIjoxNzY4MDY2NDczLCJpc3MiOiJsaWJtb2R1bG9yIiwiaWF0IjoxNzY4MDYyODczfQ.uJ8iOsCR14GN0vyH-GgG3nR2X98NTwSkwq5UnqdtLi0",
583579
},
584580
],
585581
"total": 1,
@@ -592,7 +588,7 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ANONYMOUS' and i
592588
}
593589
`;
594590

595-
exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ANONYMOUS' and input 'ONLY_MANDATORY_WITH_EXAMPLES' > hash = 24151ca8f0f48b6e4638775ac133e3aa5fef5a40b7c4696d25bf02519d44ef53 1`] = `
591+
exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ANONYMOUS' and input 'ONLY_MANDATORY_WITH_EXAMPLES' > hash = 4dfe9a0d4d3ace21d98c3edb45830564554aac3ecc9f808102a4fe6b0d0d498b 1`] = `
596592
{
597593
"out": {
598594
"args": {
@@ -602,20 +598,19 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ANONYMOUS' and i
602598
"inputFillerName": "ONLY_MANDATORY_WITH_EXAMPLES",
603599
},
604600
"err": null,
605-
"hash": "24151ca8f0f48b6e4638775ac133e3aa5fef5a40b7c4696d25bf02519d44ef53",
601+
"hash": "4dfe9a0d4d3ace21d98c3edb45830564554aac3ecc9f808102a4fe6b0d0d498b",
606602
"io": {
607603
"i": {
608604
"email": "dexter@caramail.com",
609605
"password": "fmUUNWXazWH4",
610-
"role": "admin",
611606
},
612607
"o": {
613608
"parts": {
614609
"_0": {
615610
"items": [
616611
{
617612
"id": "356a192b-7913-404c-9457-4d18c28d46e6",
618-
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcmdhbml6YXRpb24iOnsiaWQiOiJkZDk2NzBlNy0xZGQ1LTQxNTUtODVjMi0zMzU3MTQ3OTlmZjcifSwicm9sZSI6ImFkbWluIiwidXNlciI6eyJmaXJzdG5hbWUiOiJEZXh0ZXIiLCJpZCI6IjM1NmExOTJiLTc5MTMtNDA0Yy05NDU3LTRkMThjMjhkNDZlNiIsImluaXRpYWxzIjoiRE0ifSwiYXVkIjoibGlibW9kdWxvciIsImV4cCI6MTc2ODA1NDY4NCwiaXNzIjoibGlibW9kdWxvciIsImlhdCI6MTc2ODA1MTA4NH0.50t-rDF2Olqd-cJOTuFSvLtw1wUHVoWEj_3PNjmTfxw",
613+
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcmdhbml6YXRpb24iOnsiaWQiOiJkZDk2NzBlNy0xZGQ1LTQxNTUtODVjMi0zMzU3MTQ3OTlmZjcifSwicm9sZSI6InJlZ3VsYXIiLCJ1c2VyIjp7ImZpcnN0bmFtZSI6IkRleHRlciIsImlkIjoiMzU2YTE5MmItNzkxMy00MDRjLTk0NTctNGQxOGMyOGQ0NmU2IiwiaW5pdGlhbHMiOiJETSJ9LCJhdWQiOiJsaWJtb2R1bG9yIiwiZXhwIjoxNzY4MDY2NDczLCJpc3MiOiJsaWJtb2R1bG9yIiwiaWF0IjoxNzY4MDYyODczfQ.uJ8iOsCR14GN0vyH-GgG3nR2X98NTwSkwq5UnqdtLi0",
619614
},
620615
],
621616
"total": 1,
@@ -643,7 +638,6 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ANONYMOUS' and i
643638
"i": {
644639
"email": undefined,
645640
"password": undefined,
646-
"role": undefined,
647641
},
648642
"o": null,
649643
},
@@ -652,7 +646,7 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'ANONYMOUS' and i
652646
}
653647
`;
654648

655-
exports[`Run > Use Cases > 'SignUp' > should execute with auth 'REGULAR' and input 'ALL_WITH_EXAMPLES' > hash = 1f6d8d558b4d2f4dd3b73f1cb5fcbfe50be733480f13941cf7da17898331bde2 1`] = `
649+
exports[`Run > Use Cases > 'SignUp' > should execute with auth 'REGULAR' and input 'ALL_WITH_EXAMPLES' > hash = 765330b1703e4a1b1b53f308b592e21970ca086c905dc37aef8664a599b7f307 1`] = `
656650
{
657651
"out": {
658652
"args": {
@@ -672,12 +666,11 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'REGULAR' and inp
672666
"inputFillerName": "ALL_WITH_EXAMPLES",
673667
},
674668
"err": [ForbiddenError: Forbidden],
675-
"hash": "1f6d8d558b4d2f4dd3b73f1cb5fcbfe50be733480f13941cf7da17898331bde2",
669+
"hash": "765330b1703e4a1b1b53f308b592e21970ca086c905dc37aef8664a599b7f307",
676670
"io": {
677671
"i": {
678672
"email": "dexter@caramail.com",
679673
"password": "fmUUNWXazWH4",
680-
"role": "admin",
681674
},
682675
"o": null,
683676
},
@@ -686,7 +679,7 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'REGULAR' and inp
686679
}
687680
`;
688681

689-
exports[`Run > Use Cases > 'SignUp' > should execute with auth 'REGULAR' and input 'ONLY_MANDATORY_WITH_EXAMPLES' > hash = 1f1d9709da3d1a85bc371526fb2c7f13efc5df3cce88b08ffa609a3cd16feaef 1`] = `
682+
exports[`Run > Use Cases > 'SignUp' > should execute with auth 'REGULAR' and input 'ONLY_MANDATORY_WITH_EXAMPLES' > hash = aed9326e12337387670c4886d1fe6e375a8c5997f24cea7fff5d47713cbbf56e 1`] = `
690683
{
691684
"out": {
692685
"args": {
@@ -706,12 +699,11 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'REGULAR' and inp
706699
"inputFillerName": "ONLY_MANDATORY_WITH_EXAMPLES",
707700
},
708701
"err": [ForbiddenError: Forbidden],
709-
"hash": "1f1d9709da3d1a85bc371526fb2c7f13efc5df3cce88b08ffa609a3cd16feaef",
702+
"hash": "aed9326e12337387670c4886d1fe6e375a8c5997f24cea7fff5d47713cbbf56e",
710703
"io": {
711704
"i": {
712705
"email": "dexter@caramail.com",
713706
"password": "fmUUNWXazWH4",
714-
"role": "admin",
715707
},
716708
"o": null,
717709
},
@@ -745,7 +737,6 @@ exports[`Run > Use Cases > 'SignUp' > should execute with auth 'REGULAR' and inp
745737
"i": {
746738
"email": undefined,
747739
"password": undefined,
748-
"role": undefined,
749740
},
750741
"o": null,
751742
},

0 commit comments

Comments
 (0)