@meridianjs/auth 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -2
- package/dist/index.mjs +8 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,11 +2,13 @@ import * as _meridianjs_types from '@meridianjs/types';
|
|
|
2
2
|
import { MeridianContainer } from '@meridianjs/types';
|
|
3
3
|
import { Response, NextFunction } from 'express';
|
|
4
4
|
|
|
5
|
+
type UserRole = "super-admin" | "admin" | "moderator" | "member";
|
|
5
6
|
interface RegisterInput {
|
|
6
7
|
email: string;
|
|
7
8
|
password: string;
|
|
8
9
|
first_name?: string;
|
|
9
10
|
last_name?: string;
|
|
11
|
+
role?: UserRole;
|
|
10
12
|
}
|
|
11
13
|
interface LoginInput {
|
|
12
14
|
email: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,13 @@ import * as _meridianjs_types from '@meridianjs/types';
|
|
|
2
2
|
import { MeridianContainer } from '@meridianjs/types';
|
|
3
3
|
import { Response, NextFunction } from 'express';
|
|
4
4
|
|
|
5
|
+
type UserRole = "super-admin" | "admin" | "moderator" | "member";
|
|
5
6
|
interface RegisterInput {
|
|
6
7
|
email: string;
|
|
7
8
|
password: string;
|
|
8
9
|
first_name?: string;
|
|
9
10
|
last_name?: string;
|
|
11
|
+
role?: UserRole;
|
|
10
12
|
}
|
|
11
13
|
interface LoginInput {
|
|
12
14
|
email: string;
|
package/dist/index.js
CHANGED
|
@@ -61,14 +61,20 @@ var AuthModuleService = class extends (0, import_framework_utils.MeridianService
|
|
|
61
61
|
throw Object.assign(new Error("Email already registered"), { status: 409 });
|
|
62
62
|
}
|
|
63
63
|
const password_hash = await import_bcrypt.default.hash(input.password, BCRYPT_ROUNDS);
|
|
64
|
+
let role = input.role ?? "member";
|
|
65
|
+
if (!input.role) {
|
|
66
|
+
const userCount = await userService.countUsers();
|
|
67
|
+
if (userCount === 0) role = "super-admin";
|
|
68
|
+
}
|
|
64
69
|
const user = await userService.createUser({
|
|
65
70
|
email: input.email.toLowerCase().trim(),
|
|
66
71
|
password_hash,
|
|
67
72
|
first_name: input.first_name ?? null,
|
|
68
73
|
last_name: input.last_name ?? null,
|
|
74
|
+
role,
|
|
69
75
|
is_active: true
|
|
70
76
|
});
|
|
71
|
-
const token = this.signToken(user.id, null, [], config.projectConfig.jwtSecret);
|
|
77
|
+
const token = this.signToken(user.id, null, [user.role], config.projectConfig.jwtSecret);
|
|
72
78
|
return {
|
|
73
79
|
user: {
|
|
74
80
|
id: user.id,
|
|
@@ -96,7 +102,7 @@ var AuthModuleService = class extends (0, import_framework_utils.MeridianService
|
|
|
96
102
|
}
|
|
97
103
|
await userService.recordLogin(user.id).catch(() => {
|
|
98
104
|
});
|
|
99
|
-
const token = this.signToken(user.id, null, [], config.projectConfig.jwtSecret);
|
|
105
|
+
const token = this.signToken(user.id, null, [user.role ?? "member"], config.projectConfig.jwtSecret);
|
|
100
106
|
return {
|
|
101
107
|
user: {
|
|
102
108
|
id: user.id,
|
package/dist/index.mjs
CHANGED
|
@@ -22,14 +22,20 @@ var AuthModuleService = class extends MeridianService({}) {
|
|
|
22
22
|
throw Object.assign(new Error("Email already registered"), { status: 409 });
|
|
23
23
|
}
|
|
24
24
|
const password_hash = await bcrypt.hash(input.password, BCRYPT_ROUNDS);
|
|
25
|
+
let role = input.role ?? "member";
|
|
26
|
+
if (!input.role) {
|
|
27
|
+
const userCount = await userService.countUsers();
|
|
28
|
+
if (userCount === 0) role = "super-admin";
|
|
29
|
+
}
|
|
25
30
|
const user = await userService.createUser({
|
|
26
31
|
email: input.email.toLowerCase().trim(),
|
|
27
32
|
password_hash,
|
|
28
33
|
first_name: input.first_name ?? null,
|
|
29
34
|
last_name: input.last_name ?? null,
|
|
35
|
+
role,
|
|
30
36
|
is_active: true
|
|
31
37
|
});
|
|
32
|
-
const token = this.signToken(user.id, null, [], config.projectConfig.jwtSecret);
|
|
38
|
+
const token = this.signToken(user.id, null, [user.role], config.projectConfig.jwtSecret);
|
|
33
39
|
return {
|
|
34
40
|
user: {
|
|
35
41
|
id: user.id,
|
|
@@ -57,7 +63,7 @@ var AuthModuleService = class extends MeridianService({}) {
|
|
|
57
63
|
}
|
|
58
64
|
await userService.recordLogin(user.id).catch(() => {
|
|
59
65
|
});
|
|
60
|
-
const token = this.signToken(user.id, null, [], config.projectConfig.jwtSecret);
|
|
66
|
+
const token = this.signToken(user.id, null, [user.role ?? "member"], config.projectConfig.jwtSecret);
|
|
61
67
|
return {
|
|
62
68
|
user: {
|
|
63
69
|
id: user.id,
|