👔 add create account in provision
Add logic to create a new account when provisioning if not yet registered.
This commit is contained in:
22
src/modules/user/services/internal/createUser.service.ts
Normal file
22
src/modules/user/services/internal/createUser.service.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||
import { hashPassword } from "../../../../helpers/security/password/hash";
|
||||
import { createUserViaRegisterRepository } from "../../repositories/create/createUserViaRegister.repository";
|
||||
import {
|
||||
createUserViaOauth,
|
||||
createUserViaRegisterInput,
|
||||
} from "../../user.types";
|
||||
|
||||
export const createUserService = async (
|
||||
payload: createUserViaRegisterInput | createUserViaOauth
|
||||
) => {
|
||||
try {
|
||||
const hashedPassword = await hashPassword(payload.password);
|
||||
|
||||
return await createUserViaRegisterRepository({
|
||||
...payload,
|
||||
password: hashedPassword,
|
||||
});
|
||||
} catch (error) {
|
||||
ErrorForwarder(error);
|
||||
}
|
||||
};
|
||||
@ -15,3 +15,15 @@ export interface createUserViaRegisterInput {
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
export interface createUserViaOauth {
|
||||
provider: string;
|
||||
providerId: string;
|
||||
providerToken?: string;
|
||||
providerPayload?: unknown;
|
||||
email: string;
|
||||
username: string;
|
||||
name: string;
|
||||
avatar?: string;
|
||||
bio?: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user