create-warlock 2.6.1 → 2.7.0
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/package.json +1 -1
- package/templates/warlock/.env +39 -0
- package/templates/warlock/.env.example +35 -35
- package/templates/warlock/.gitattributes +1 -1
- package/templates/warlock/package.json +9 -7
- package/templates/warlock/src/app/main.ts +43 -12
- package/templates/warlock/src/app/posts/controllers/create-new-post.request.ts +26 -0
- package/templates/warlock/src/app/posts/controllers/get-all-posts.request.ts +17 -0
- package/templates/warlock/src/app/posts/controllers/get-post.request.ts +37 -0
- package/templates/warlock/src/app/posts/models/index.ts +1 -0
- package/templates/warlock/src/app/posts/models/post.model.ts +22 -0
- package/templates/warlock/src/app/posts/output/post.output.ts +13 -0
- package/templates/warlock/src/app/posts/routes.ts +12 -0
- package/templates/warlock/src/app/uploads/routes.ts +27 -27
- package/templates/warlock/src/app/users/controllers/auth/admin-login.ts +40 -40
- package/templates/warlock/src/app/users/controllers/auth/login.request.ts +28 -49
- package/templates/warlock/src/app/users/controllers/auth/logout.ts +10 -10
- package/templates/warlock/src/app/users/controllers/auth/register.request.ts +24 -0
- package/templates/warlock/src/app/users/controllers/auth/resend-activation-code.ts +45 -45
- package/templates/warlock/src/app/users/controllers/auth/reset-password.ts +43 -43
- package/templates/warlock/src/app/users/controllers/auth/verify-forget-password-code.ts +18 -18
- package/templates/warlock/src/app/users/controllers/profile/change-password.ts +31 -31
- package/templates/warlock/src/app/users/controllers/profile/my-profile.ts +10 -10
- package/templates/warlock/src/app/users/controllers/profile/update-profile.ts +25 -25
- package/templates/warlock/src/app/users/controllers/restful-users.ts +26 -26
- package/templates/warlock/src/app/users/events/attach-user-to-response.ts +18 -18
- package/templates/warlock/src/app/users/events/register-current-user-to-model-authors.ts +28 -28
- package/templates/warlock/src/app/users/events/update-authors.ts +19 -19
- package/templates/warlock/src/app/users/mail/send-forget-password-email.ts +20 -20
- package/templates/warlock/src/app/users/models/user/index.ts +1 -1
- package/templates/warlock/src/app/users/models/user/migrations/20-10-2024_07-59-54-user.migration.ts +15 -15
- package/templates/warlock/src/app/users/models/user/user.model.ts +59 -54
- package/templates/warlock/src/app/users/output/user.output.ts +12 -12
- package/templates/warlock/src/app/users/routes.ts +51 -51
- package/templates/warlock/src/app/users/utils/locales.ts +16 -16
- package/templates/warlock/src/app/utils/output.ts +18 -18
- package/templates/warlock/src/app/utils/router.ts +104 -104
- package/templates/warlock/src/config/database.ts +4 -0
|
@@ -1,54 +1,59 @@
|
|
|
1
|
-
import { Auth, castPassword } from "@warlock.js/auth";
|
|
2
|
-
import type { Casts, Document } from "@warlock.js/cascade";
|
|
3
|
-
import { castEmail, expiresAfter } from "@warlock.js/cascade";
|
|
4
|
-
import { uploadable } from "@warlock.js/core";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
import { Auth, castPassword } from "@warlock.js/auth";
|
|
2
|
+
import type { Casts, Document, Joinable } from "@warlock.js/cascade";
|
|
3
|
+
import { castEmail, expiresAfter } from "@warlock.js/cascade";
|
|
4
|
+
import { uploadable } from "@warlock.js/core";
|
|
5
|
+
import { Post } from "../../../posts/models";
|
|
6
|
+
import { UserOutput } from "../../output/user.output";
|
|
7
|
+
|
|
8
|
+
export class User extends Auth {
|
|
9
|
+
/**
|
|
10
|
+
* Collection name
|
|
11
|
+
*/
|
|
12
|
+
public static collection = "users";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Output
|
|
16
|
+
*/
|
|
17
|
+
public static output = UserOutput;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* {@inheritdoc}
|
|
21
|
+
*/
|
|
22
|
+
public syncWith = [];
|
|
23
|
+
|
|
24
|
+
public static relations: Record<string, Joinable> = {
|
|
25
|
+
totalPosts: Post.joinable("id", "author.id"),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get user type
|
|
30
|
+
*/
|
|
31
|
+
public get userType(): string {
|
|
32
|
+
return "user";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* {@inheritDoc}
|
|
37
|
+
*/
|
|
38
|
+
public defaultValue: Document = {
|
|
39
|
+
isActive: false,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* {@inheritDoc}
|
|
44
|
+
*/
|
|
45
|
+
protected casts: Casts = {
|
|
46
|
+
name: "string",
|
|
47
|
+
isActive: "boolean",
|
|
48
|
+
image: uploadable,
|
|
49
|
+
email: castEmail,
|
|
50
|
+
password: castPassword,
|
|
51
|
+
activationCode: "int",
|
|
52
|
+
codeExpiresAt: expiresAfter(30, "minutes"),
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* {@inheritdoc}
|
|
57
|
+
*/
|
|
58
|
+
public embedded = ["id", "name", "email"];
|
|
59
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Output, type FinalOutput } from "@warlock.js/core";
|
|
2
|
-
import { withBaseOutputDetails } from "app/utils/output";
|
|
3
|
-
|
|
4
|
-
export class UserOutput extends Output {
|
|
5
|
-
/**
|
|
6
|
-
* Output data
|
|
7
|
-
*/
|
|
8
|
-
protected output: FinalOutput = withBaseOutputDetails({
|
|
9
|
-
name: "string",
|
|
10
|
-
email: "string",
|
|
11
|
-
});
|
|
12
|
-
}
|
|
1
|
+
import { Output, type FinalOutput } from "@warlock.js/core";
|
|
2
|
+
import { withBaseOutputDetails } from "app/utils/output";
|
|
3
|
+
|
|
4
|
+
export class UserOutput extends Output {
|
|
5
|
+
/**
|
|
6
|
+
* Output data
|
|
7
|
+
*/
|
|
8
|
+
protected output: FinalOutput = withBaseOutputDetails({
|
|
9
|
+
name: "string",
|
|
10
|
+
email: "string",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import { router } from "@warlock.js/core";
|
|
2
|
-
import {
|
|
3
|
-
guarded,
|
|
4
|
-
guardedAdmin,
|
|
5
|
-
guardedGuest,
|
|
6
|
-
guardedGuestAdmin,
|
|
7
|
-
} from "app/utils/router";
|
|
8
|
-
import activateAccount from "./controllers/auth/activate-account";
|
|
9
|
-
import adminLogin from "./controllers/auth/admin-login";
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import resendActivationCode from "./controllers/auth/resend-activation-code";
|
|
15
|
-
import resetPassword from "./controllers/auth/reset-password";
|
|
16
|
-
import verifyForgetPasswordCode from "./controllers/auth/verify-forget-password-code";
|
|
17
|
-
import changePassword from "./controllers/profile/change-password";
|
|
18
|
-
import myProfile from "./controllers/profile/my-profile";
|
|
19
|
-
import updateProfile from "./controllers/profile/update-profile";
|
|
20
|
-
import { restfulUsers } from "./controllers/restful-users";
|
|
21
|
-
|
|
22
|
-
// admin auth
|
|
23
|
-
guardedGuestAdmin(() => {
|
|
24
|
-
router.post("/login", adminLogin);
|
|
25
|
-
router.post("/forget-password", forgetPassword);
|
|
26
|
-
router.post("/reset-password", resetPassword);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
guardedAdmin(() => {
|
|
30
|
-
// REST API for users
|
|
31
|
-
router.restfulResource("/users", restfulUsers);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// user auth
|
|
35
|
-
guardedGuest(() => {
|
|
36
|
-
router.post("/login",
|
|
37
|
-
router.post("/register",
|
|
38
|
-
router.post("/register/verify", activateAccount);
|
|
39
|
-
router.post("/resend-activation-code", resendActivationCode);
|
|
40
|
-
router.post("/forget-password", forgetPassword);
|
|
41
|
-
router.post("/forget-password/verify-code", verifyForgetPasswordCode);
|
|
42
|
-
router.post("/reset-password", resetPassword);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// profile routes
|
|
46
|
-
guarded(() => {
|
|
47
|
-
router.get("/me", myProfile);
|
|
48
|
-
router.post("/me", updateProfile);
|
|
49
|
-
router.post("/logout", logout);
|
|
50
|
-
router.post("/change-password", changePassword);
|
|
51
|
-
});
|
|
1
|
+
import { router } from "@warlock.js/core";
|
|
2
|
+
import {
|
|
3
|
+
guarded,
|
|
4
|
+
guardedAdmin,
|
|
5
|
+
guardedGuest,
|
|
6
|
+
guardedGuestAdmin,
|
|
7
|
+
} from "app/utils/router";
|
|
8
|
+
import activateAccount from "./controllers/auth/activate-account";
|
|
9
|
+
import adminLogin from "./controllers/auth/admin-login";
|
|
10
|
+
import forgetPassword from "./controllers/auth/forget-password";
|
|
11
|
+
import { loginRequest } from "./controllers/auth/login.request";
|
|
12
|
+
import logout from "./controllers/auth/logout";
|
|
13
|
+
import { registerRequest } from "./controllers/auth/register.request";
|
|
14
|
+
import resendActivationCode from "./controllers/auth/resend-activation-code";
|
|
15
|
+
import resetPassword from "./controllers/auth/reset-password";
|
|
16
|
+
import verifyForgetPasswordCode from "./controllers/auth/verify-forget-password-code";
|
|
17
|
+
import changePassword from "./controllers/profile/change-password";
|
|
18
|
+
import myProfile from "./controllers/profile/my-profile";
|
|
19
|
+
import updateProfile from "./controllers/profile/update-profile";
|
|
20
|
+
import { restfulUsers } from "./controllers/restful-users";
|
|
21
|
+
|
|
22
|
+
// admin auth
|
|
23
|
+
guardedGuestAdmin(() => {
|
|
24
|
+
router.post("/login", adminLogin);
|
|
25
|
+
router.post("/forget-password", forgetPassword);
|
|
26
|
+
router.post("/reset-password", resetPassword);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
guardedAdmin(() => {
|
|
30
|
+
// REST API for users
|
|
31
|
+
router.restfulResource("/users", restfulUsers);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// user auth
|
|
35
|
+
guardedGuest(() => {
|
|
36
|
+
router.post("/login", loginRequest);
|
|
37
|
+
router.post("/register", registerRequest);
|
|
38
|
+
router.post("/register/verify", activateAccount);
|
|
39
|
+
router.post("/resend-activation-code", resendActivationCode);
|
|
40
|
+
router.post("/forget-password", forgetPassword);
|
|
41
|
+
router.post("/forget-password/verify-code", verifyForgetPasswordCode);
|
|
42
|
+
router.post("/reset-password", resetPassword);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// profile routes
|
|
46
|
+
guarded(() => {
|
|
47
|
+
router.get("/me", myProfile);
|
|
48
|
+
router.post("/me", updateProfile);
|
|
49
|
+
router.post("/logout", logout);
|
|
50
|
+
router.post("/change-password", changePassword);
|
|
51
|
+
});
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { groupedTranslations } from "@mongez/localization";
|
|
2
|
-
|
|
3
|
-
groupedTranslations("auth", {
|
|
4
|
-
confirmRegistrationSubject: {
|
|
5
|
-
en: "Activate your account",
|
|
6
|
-
ar: "تفعيل حسابك",
|
|
7
|
-
},
|
|
8
|
-
invalidCredentials: {
|
|
9
|
-
en: "Invalid credentials",
|
|
10
|
-
ar: "بيانات الدخول غير صحيحة",
|
|
11
|
-
},
|
|
12
|
-
accountNotActivated: {
|
|
13
|
-
en: "Your account is not activated",
|
|
14
|
-
ar: "حسابك غير مفعل",
|
|
15
|
-
},
|
|
16
|
-
});
|
|
1
|
+
import { groupedTranslations } from "@mongez/localization";
|
|
2
|
+
|
|
3
|
+
groupedTranslations("auth", {
|
|
4
|
+
confirmRegistrationSubject: {
|
|
5
|
+
en: "Activate your account",
|
|
6
|
+
ar: "تفعيل حسابك",
|
|
7
|
+
},
|
|
8
|
+
invalidCredentials: {
|
|
9
|
+
en: "Invalid credentials",
|
|
10
|
+
ar: "بيانات الدخول غير صحيحة",
|
|
11
|
+
},
|
|
12
|
+
accountNotActivated: {
|
|
13
|
+
en: "Your account is not activated",
|
|
14
|
+
ar: "حسابك غير مفعل",
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { FinalOutput } from "@warlock.js/core";
|
|
2
|
-
import { UserOutput } from "app/users/output/user.output";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Merge the output with this function will return the base output details
|
|
6
|
-
* Only and only if any of these keys are present
|
|
7
|
-
*/
|
|
8
|
-
export function withBaseOutputDetails(moreOptions: FinalOutput): FinalOutput {
|
|
9
|
-
return {
|
|
10
|
-
id: "integer",
|
|
11
|
-
isActive: "boolean",
|
|
12
|
-
createdAt: "date",
|
|
13
|
-
updatedAt: "date",
|
|
14
|
-
createdBy: UserOutput,
|
|
15
|
-
updatedBy: UserOutput,
|
|
16
|
-
...moreOptions,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
1
|
+
import type { FinalOutput } from "@warlock.js/core";
|
|
2
|
+
import { UserOutput } from "app/users/output/user.output";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Merge the output with this function will return the base output details
|
|
6
|
+
* Only and only if any of these keys are present
|
|
7
|
+
*/
|
|
8
|
+
export function withBaseOutputDetails(moreOptions: FinalOutput): FinalOutput {
|
|
9
|
+
return {
|
|
10
|
+
id: "integer",
|
|
11
|
+
isActive: "boolean",
|
|
12
|
+
createdAt: "date",
|
|
13
|
+
updatedAt: "date",
|
|
14
|
+
createdBy: UserOutput,
|
|
15
|
+
updatedBy: UserOutput,
|
|
16
|
+
...moreOptions,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
import { authMiddleware } from "@warlock.js/auth";
|
|
2
|
-
import {
|
|
3
|
-
router,
|
|
4
|
-
useRequestStore,
|
|
5
|
-
type Middleware,
|
|
6
|
-
type RouterGroupCallback,
|
|
7
|
-
} from "@warlock.js/core";
|
|
8
|
-
|
|
9
|
-
export const adminPath = (path: string) => `/admin${path}`;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Check if the current request is for admin
|
|
13
|
-
*/
|
|
14
|
-
export const isAdminRequest = () => {
|
|
15
|
-
const { request } = useRequestStore();
|
|
16
|
-
|
|
17
|
-
return request.path.includes("/admin");
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Add routes Group
|
|
22
|
-
*/
|
|
23
|
-
const adminRoutes = (callback: RouterGroupCallback) => {
|
|
24
|
-
return router.group(
|
|
25
|
-
{
|
|
26
|
-
prefix: "/admin",
|
|
27
|
-
name: "admin",
|
|
28
|
-
},
|
|
29
|
-
callback,
|
|
30
|
-
);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Register guarded routes that requires user to be logged in to access them.
|
|
35
|
-
*/
|
|
36
|
-
export const guarded = (
|
|
37
|
-
callback: RouterGroupCallback,
|
|
38
|
-
moreMiddlewares: Middleware[] = [],
|
|
39
|
-
) => {
|
|
40
|
-
return router.group(
|
|
41
|
-
{
|
|
42
|
-
name: "guarded.user",
|
|
43
|
-
middleware: [authMiddleware("user"), ...moreMiddlewares],
|
|
44
|
-
},
|
|
45
|
-
callback,
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Only guests can access these routes.
|
|
51
|
-
*/
|
|
52
|
-
export const guardedGuest = (callback: RouterGroupCallback) => {
|
|
53
|
-
return router.group(
|
|
54
|
-
{
|
|
55
|
-
name: "guarded.guest",
|
|
56
|
-
middleware: [authMiddleware()],
|
|
57
|
-
},
|
|
58
|
-
callback,
|
|
59
|
-
);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Guarded guest routes for admin
|
|
64
|
-
*/
|
|
65
|
-
export const guardedGuestAdmin = (callback: RouterGroupCallback) => {
|
|
66
|
-
return adminRoutes(() => {
|
|
67
|
-
router.group(
|
|
68
|
-
{
|
|
69
|
-
name: "guarded.guest",
|
|
70
|
-
middleware: [authMiddleware()],
|
|
71
|
-
},
|
|
72
|
-
callback,
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Only admin can access these routes.
|
|
79
|
-
*/
|
|
80
|
-
export const guardedAdmin = (callback: RouterGroupCallback) => {
|
|
81
|
-
return adminRoutes(() => {
|
|
82
|
-
router.group(
|
|
83
|
-
{
|
|
84
|
-
name: "guarded.user",
|
|
85
|
-
middleware: [authMiddleware("user")],
|
|
86
|
-
},
|
|
87
|
-
callback,
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Public routes that doesn't require user to be logged in to access them.
|
|
94
|
-
* Just requires an access token.
|
|
95
|
-
*/
|
|
96
|
-
export const publicRoutes = (callback: RouterGroupCallback) => {
|
|
97
|
-
return router.group(
|
|
98
|
-
{
|
|
99
|
-
name: "public",
|
|
100
|
-
middleware: [authMiddleware()],
|
|
101
|
-
},
|
|
102
|
-
callback,
|
|
103
|
-
);
|
|
104
|
-
};
|
|
1
|
+
import { authMiddleware } from "@warlock.js/auth";
|
|
2
|
+
import {
|
|
3
|
+
router,
|
|
4
|
+
useRequestStore,
|
|
5
|
+
type Middleware,
|
|
6
|
+
type RouterGroupCallback,
|
|
7
|
+
} from "@warlock.js/core";
|
|
8
|
+
|
|
9
|
+
export const adminPath = (path: string) => `/admin${path}`;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Check if the current request is for admin
|
|
13
|
+
*/
|
|
14
|
+
export const isAdminRequest = () => {
|
|
15
|
+
const { request } = useRequestStore();
|
|
16
|
+
|
|
17
|
+
return request.path.includes("/admin");
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Add routes Group
|
|
22
|
+
*/
|
|
23
|
+
const adminRoutes = (callback: RouterGroupCallback) => {
|
|
24
|
+
return router.group(
|
|
25
|
+
{
|
|
26
|
+
prefix: "/admin",
|
|
27
|
+
name: "admin",
|
|
28
|
+
},
|
|
29
|
+
callback,
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Register guarded routes that requires user to be logged in to access them.
|
|
35
|
+
*/
|
|
36
|
+
export const guarded = (
|
|
37
|
+
callback: RouterGroupCallback,
|
|
38
|
+
moreMiddlewares: Middleware[] = [],
|
|
39
|
+
) => {
|
|
40
|
+
return router.group(
|
|
41
|
+
{
|
|
42
|
+
name: "guarded.user",
|
|
43
|
+
middleware: [authMiddleware("user"), ...moreMiddlewares],
|
|
44
|
+
},
|
|
45
|
+
callback,
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Only guests can access these routes.
|
|
51
|
+
*/
|
|
52
|
+
export const guardedGuest = (callback: RouterGroupCallback) => {
|
|
53
|
+
return router.group(
|
|
54
|
+
{
|
|
55
|
+
name: "guarded.guest",
|
|
56
|
+
middleware: [authMiddleware()],
|
|
57
|
+
},
|
|
58
|
+
callback,
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Guarded guest routes for admin
|
|
64
|
+
*/
|
|
65
|
+
export const guardedGuestAdmin = (callback: RouterGroupCallback) => {
|
|
66
|
+
return adminRoutes(() => {
|
|
67
|
+
router.group(
|
|
68
|
+
{
|
|
69
|
+
name: "guarded.guest",
|
|
70
|
+
middleware: [authMiddleware()],
|
|
71
|
+
},
|
|
72
|
+
callback,
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Only admin can access these routes.
|
|
79
|
+
*/
|
|
80
|
+
export const guardedAdmin = (callback: RouterGroupCallback) => {
|
|
81
|
+
return adminRoutes(() => {
|
|
82
|
+
router.group(
|
|
83
|
+
{
|
|
84
|
+
name: "guarded.user",
|
|
85
|
+
middleware: [authMiddleware("user")],
|
|
86
|
+
},
|
|
87
|
+
callback,
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Public routes that doesn't require user to be logged in to access them.
|
|
94
|
+
* Just requires an access token.
|
|
95
|
+
*/
|
|
96
|
+
export const publicRoutes = (callback: RouterGroupCallback) => {
|
|
97
|
+
return router.group(
|
|
98
|
+
{
|
|
99
|
+
name: "public",
|
|
100
|
+
middleware: [authMiddleware()],
|
|
101
|
+
},
|
|
102
|
+
callback,
|
|
103
|
+
);
|
|
104
|
+
};
|