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
+1
View File
@@ -154,6 +154,7 @@ export const initializeSamlStrategy = async () => {
firstName, firstName,
lastName, lastName,
organizationName: organization?.name, organizationName: organization?.name,
organizationId: organization?._id,
authMethod: req.ssoConfig.authProvider, authMethod: req.ssoConfig.authProvider,
isUserCompleted, isUserCompleted,
...(req.body.RelayState ? { ...(req.body.RelayState ? {
+7 -1
View File
@@ -2,9 +2,15 @@ import { NextRouter } from "next/router";
import { fetchOrganizations } from "@app/hooks/api/organization/queries"; 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(); const userOrgs = await fetchOrganizations();
if (organizationId) {
localStorage.setItem("orgData.id", organizationId);
router.push(`/org/${organizationId}/overview`);
return;
}
if (userOrgs.length > 0) { if (userOrgs.length > 0) {
// user is part of at least 1 org // user is part of at least 1 org
const userOrg = userOrgs[0] && userOrgs[0]._id; const userOrg = userOrgs[0] && userOrgs[0]._id;
@@ -78,6 +78,7 @@ export const MFAStep = ({
let isLinkingRequired: undefined | boolean; let isLinkingRequired: undefined | boolean;
let callbackPort: undefined | string; let callbackPort: undefined | string;
let authMethod: undefined | AuthMethod; let authMethod: undefined | AuthMethod;
let organizationId: undefined | string;
if (providerAuthToken) { if (providerAuthToken) {
const decodedToken = jwt_decode(providerAuthToken) as any; const decodedToken = jwt_decode(providerAuthToken) as any;
@@ -85,6 +86,7 @@ export const MFAStep = ({
isLinkingRequired = decodedToken.isLinkingRequired; isLinkingRequired = decodedToken.isLinkingRequired;
callbackPort = decodedToken.callbackPort; callbackPort = decodedToken.callbackPort;
authMethod = decodedToken.authMethod; authMethod = decodedToken.authMethod;
organizationId = decodedToken?.organizationId;
} }
if (mfaCode.length !== 6) { if (mfaCode.length !== 6) {
@@ -142,7 +144,7 @@ export const MFAStep = ({
}); });
} }
await navigateUserToOrg(router); await navigateUserToOrg(router, organizationId);
} else { } else {
createNotification({ createNotification({
text: "Failed to log in", text: "Failed to log in",
@@ -38,7 +38,8 @@ export const PasswordStep = ({
const { const {
callbackPort, callbackPort,
isLinkingRequired, isLinkingRequired,
authMethod authMethod,
organizationId
} = jwt_decode(providerAuthToken) as any; } = jwt_decode(providerAuthToken) as any;
const handleLogin = async (e:React.FormEvent) => { const handleLogin = async (e:React.FormEvent) => {
@@ -107,7 +108,7 @@ export const PasswordStep = ({
}); });
} }
await navigateUserToOrg(router); await navigateUserToOrg(router, organizationId);
} }
} }
} catch (err) { } catch (err) {
+1 -1
View File
@@ -19,7 +19,7 @@ export const SignupSSO = ({
email, email,
organizationName, organizationName,
firstName, firstName,
lastName lastName,
} = jwt_decode(providerAuthToken) as any; } = jwt_decode(providerAuthToken) as any;
const renderView = () => { const renderView = () => {