Fix: Email signup and switching organization

This commit is contained in:
Daniel Hougaard
2024-03-17 18:49:30 +01:00
parent 605dad29ca
commit 4d229ec745
4 changed files with 40 additions and 16 deletions
@@ -150,11 +150,15 @@ export const authSignupServiceFactory = ({
});
if (!organizationId) {
await orgService.createOrganization({
const newOrganization = await orgService.createOrganization({
userId: user.id,
userEmail: user.email ?? user.username,
orgName: organizationName
});
if (!newOrganization) throw new Error("Failed to create organization");
organizationId = newOrganization.id;
}
const updatedMembersips = await orgDAL.updateMembership(
@@ -187,6 +191,7 @@ export const authSignupServiceFactory = ({
const refreshToken = jwt.sign(
{
authMethod: AuthMethod.EMAIL,
authTokenType: AuthTokenType.REFRESH_TOKEN,
userId: updateduser.info.id,
tokenVersionId: tokenSession.id,
@@ -197,7 +202,7 @@ export const authSignupServiceFactory = ({
{ expiresIn: appCfg.JWT_REFRESH_LIFETIME }
);
return { user: updateduser.info, accessToken, refreshToken };
return { user: updateduser.info, accessToken, refreshToken, organizationId };
};
/*
@@ -290,6 +295,7 @@ export const authSignupServiceFactory = ({
const refreshToken = jwt.sign(
{
authMethod: AuthMethod.EMAIL,
authTokenType: AuthTokenType.REFRESH_TOKEN,
userId: updateduser.info.id,
tokenVersionId: tokenSession.id,