Skip to content

Commit

Permalink
fix:(login) Admin should be able to login after signup #579
Browse files Browse the repository at this point in the history
  • Loading branch information
mpanoathos committed Oct 16, 2024
1 parent c99966a commit 2a508f4
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/resolvers/userResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,22 @@ const resolvers: any = {
{ user },
{ $push: { activity: { $each: [newActivity] } } }
)
if (user?.role === RoleOfUser.ADMIN) {
const organization = await Organization.findOne({
name: org?.name,
admin: user.id,
});
if (organization) {
const token = generateToken(user._id, user._doc?.role || 'user');
const data = {
token: token,
user: user.toJSON(),
};
return data;
} else {
throw new Error('Organization not found for the admin.');
}
}
if (
user?.role === RoleOfUser.TRAINEE &&
user?.organizations?.includes(org?.name)
Expand Down Expand Up @@ -392,19 +408,12 @@ const resolvers: any = {
throw new Error('You are not assigned to any cohort ot team yet.')
}
}
const organization: any = await Organization.findOne({
name: org?.name,
admin: user.id,
})
// const organization: any = await Organization.findOne({
// name: org?.name,
// admin: user.id,
// })

if (user?.role === RoleOfUser.ADMIN && organization) {
const token = generateToken(user._id, user._doc?.role || 'user')
const data = {
token: token,
user: user.toJSON(),
}
return data
} else if (user?.role === RoleOfUser.MANAGER) {
else if (user?.role === RoleOfUser.MANAGER) {
const program: any = await Program.find({
manager: user.id,
}).populate({
Expand Down

0 comments on commit 2a508f4

Please sign in to comment.