Update redirect to org after SSO

This commit is contained in:
Tuan Dang
2023-12-14 23:07:22 +07:00
parent 8e0f424249
commit 51b788cc5b
5 changed files with 16 additions and 6 deletions

View File

@@ -75,7 +75,7 @@ export const initializeSamlStrategy = async () => {
const organization = await Organization.findById(req.ssoConfig.organization);
if (!organization) return done(OrganizationNotFoundError());
const email = profile.email;
const firstName = profile.firstName;
const lastName = profile.lastName;
@@ -154,6 +154,7 @@ export const initializeSamlStrategy = async () => {
firstName,
lastName,
organizationName: organization?.name,
organizationId: organization?._id,
authMethod: req.ssoConfig.authProvider,
isUserCompleted,
...(req.body.RelayState ? {

View File

@@ -2,9 +2,15 @@ import { NextRouter } from "next/router";
import { fetchOrganizations } from "@app/hooks/api/organization/queries";
export const navigateUserToOrg = async (router: NextRouter) => {
export const navigateUserToOrg = async (router: NextRouter, organizationId?: string) => {
const userOrgs = await fetchOrganizations();
if (organizationId) {
localStorage.setItem("orgData.id", organizationId);
router.push(`/org/${organizationId}/overview`);
return;
}
if (userOrgs.length > 0) {
// user is part of at least 1 org
const userOrg = userOrgs[0] && userOrgs[0]._id;

View File

@@ -78,6 +78,7 @@ export const MFAStep = ({
let isLinkingRequired: undefined | boolean;
let callbackPort: undefined | string;
let authMethod: undefined | AuthMethod;
let organizationId: undefined | string;
if (providerAuthToken) {
const decodedToken = jwt_decode(providerAuthToken) as any;
@@ -85,6 +86,7 @@ export const MFAStep = ({
isLinkingRequired = decodedToken.isLinkingRequired;
callbackPort = decodedToken.callbackPort;
authMethod = decodedToken.authMethod;
organizationId = decodedToken?.organizationId;
}
if (mfaCode.length !== 6) {
@@ -142,7 +144,7 @@ export const MFAStep = ({
});
}
await navigateUserToOrg(router);
await navigateUserToOrg(router, organizationId);
} else {
createNotification({
text: "Failed to log in",

View File

@@ -38,7 +38,8 @@ export const PasswordStep = ({
const {
callbackPort,
isLinkingRequired,
authMethod
authMethod,
organizationId
} = jwt_decode(providerAuthToken) as any;
const handleLogin = async (e:React.FormEvent) => {
@@ -107,7 +108,7 @@ export const PasswordStep = ({
});
}
await navigateUserToOrg(router);
await navigateUserToOrg(router, organizationId);
}
}
} catch (err) {

View File

@@ -19,7 +19,7 @@ export const SignupSSO = ({
email,
organizationName,
firstName,
lastName
lastName,
} = jwt_decode(providerAuthToken) as any;
const renderView = () => {