Skip to content

Commit

Permalink
feat: add role config for user plugin (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pujan Khadka committed Mar 8, 2023
1 parent 81cfb5b commit 40a5402
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/user/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ declare module "@dzangolab/fastify-config" {
features?: {
signUp?: boolean;
};
role?: string;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const emailPasswordSignUpPOST = (
originalImplementation: APIInterface,
fastify: FastifyInstance
): typeof originalImplementation.emailPasswordSignUpPOST => {
const { log } = fastify;
const { log, config } = fastify;

return async (input) => {
if (originalImplementation.emailPasswordSignUpPOST === undefined) {
Expand All @@ -21,7 +21,7 @@ const emailPasswordSignUpPOST = (
if (originalResponse.status === "OK") {
const rolesResponse = await UserRoles.addRoleToUser(
originalResponse.user.id,
"USER"
config.user.role || "USER"
);

if (rolesResponse.status !== "OK") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const thirdPartySignInUpPOST = (
originalImplementation: APIInterface,
fastify: FastifyInstance
): typeof originalImplementation.thirdPartySignInUpPOST => {
const { log } = fastify;
const { log, config } = fastify;

return async (input) => {
if (originalImplementation.thirdPartySignInUpPOST === undefined) {
Expand All @@ -21,7 +21,7 @@ const thirdPartySignInUpPOST = (
if (originalResponse.status === "OK" && originalResponse.createdNewUser) {
const rolesResponse = await UserRoles.addRoleToUser(
originalResponse.user.id,
"USER"
config.user.role || "USER"
);

if (rolesResponse.status !== "OK") {
Expand Down

0 comments on commit 40a5402

Please sign in to comment.