mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 14:27:30 +00:00
Merge pull request #180 from akhilmhdh/fix/failed-workspace-membership-invite
fix(backend): resolved workspace membership invite failure
This commit is contained in:
@@ -218,12 +218,6 @@ export const verifyUserToOrganization = async (req: Request, res: Response) => {
|
|||||||
const { email, code } = req.body;
|
const { email, code } = req.body;
|
||||||
|
|
||||||
user = await User.findOne({ email }).select('+publicKey');
|
user = await User.findOne({ email }).select('+publicKey');
|
||||||
if (user && user?.publicKey) {
|
|
||||||
// case: user has already completed account
|
|
||||||
return res.status(403).send({
|
|
||||||
error: 'Failed email magic link verification for complete account'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const membershipOrg = await MembershipOrg.findOne({
|
const membershipOrg = await MembershipOrg.findOne({
|
||||||
inviteEmail: email,
|
inviteEmail: email,
|
||||||
@@ -238,6 +232,18 @@ export const verifyUserToOrganization = async (req: Request, res: Response) => {
|
|||||||
code
|
code
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (user && user?.publicKey) {
|
||||||
|
// case: user has already completed account
|
||||||
|
// membership can be approved and redirected to login/dashboard
|
||||||
|
membershipOrg.status = ACCEPTED;
|
||||||
|
await membershipOrg.save();
|
||||||
|
|
||||||
|
return res.status(200).send({
|
||||||
|
message: 'Successfully verified email',
|
||||||
|
user,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
// initialize user account
|
// initialize user account
|
||||||
user = await new User({
|
user = await new User({
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const validateMembership = async ({
|
|||||||
membership = await Membership.findOne({
|
membership = await Membership.findOne({
|
||||||
user: userId,
|
user: userId,
|
||||||
workspace: workspaceId
|
workspace: workspaceId
|
||||||
});
|
}).populate("workspace");
|
||||||
|
|
||||||
if (!membership) throw new Error('Failed to find membership');
|
if (!membership) throw new Error('Failed to find membership');
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export default function RouteGuard({ children }) {
|
|||||||
// Check if the user is authenticated
|
// Check if the user is authenticated
|
||||||
const response = await checkAuth();
|
const response = await checkAuth();
|
||||||
// #TODO: figure our why sometimes it doesn't output a response
|
// #TODO: figure our why sometimes it doesn't output a response
|
||||||
|
// ANS(akhilmhdh): Because inside the security client the await token() doesn't have try/catch
|
||||||
if (!publicPaths.includes(path)) {
|
if (!publicPaths.includes(path)) {
|
||||||
try {
|
try {
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
|
|||||||
@@ -16,12 +16,19 @@ export default class SecurityClient {
|
|||||||
const req = new Request(resource, options);
|
const req = new Request(resource, options);
|
||||||
|
|
||||||
if (this.#token == '') {
|
if (this.#token == '') {
|
||||||
this.setToken(await token());
|
try {
|
||||||
|
// TODO: This should be moved to a context to do it only once when app loads
|
||||||
|
// this try catch saves route guard from a stuck state
|
||||||
|
this.setToken(await token());
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Unauthorized access");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.#token) {
|
if (this.#token) {
|
||||||
req.headers.set('Authorization', 'Bearer ' + this.#token);
|
req.headers.set('Authorization', 'Bearer ' + this.#token);
|
||||||
return fetch(req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fetch(req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,7 @@ const checkAuth = async () => {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
}).then((res) => {
|
}).then((res) => res);
|
||||||
if (res && res.status == 200) {
|
|
||||||
return res;
|
|
||||||
} else {
|
|
||||||
console.log('Not authorized');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default checkAuth;
|
export default checkAuth;
|
||||||
|
|||||||
@@ -159,8 +159,17 @@ export default function SignupInvite() {
|
|||||||
code: token
|
code: token
|
||||||
});
|
});
|
||||||
if (response.status == 200) {
|
if (response.status == 200) {
|
||||||
setVerificationToken((await response.json()).token);
|
const res = await response.json();
|
||||||
setStep(2);
|
// user will have temp token if doesn't have an account
|
||||||
|
// then continue with account setup workflow
|
||||||
|
if(res?.token){
|
||||||
|
setVerificationToken(res.token);
|
||||||
|
setStep(2);
|
||||||
|
} else {
|
||||||
|
// user will be redirected to dashboard
|
||||||
|
// if not logged in gets kicked out to login
|
||||||
|
router.push("/dashboard")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('ERROR', response);
|
console.log('ERROR', response);
|
||||||
router.push('/requestnewinvite');
|
router.push('/requestnewinvite');
|
||||||
|
|||||||
Reference in New Issue
Block a user