Skip to content

Commit b8356fd

Browse files
Auth: redirect to org's auth url if we get orgId in app view endpoint
1 parent 35d7ac4 commit b8356fd

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

client/packages/lowcoder/src/api/apiUtils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,13 @@ export const apiFailureResponseInterceptor = (error: any) => {
121121
// Need authorization
122122
if (!notAuthRequiredPath(error.config?.url)) {
123123
if (error.response.status === API_STATUS_CODES.REQUEST_NOT_AUTHORISED) {
124+
// get x-org-id from failed request
125+
const organizationId = error.response.headers['x-org-id'] || undefined;
124126
// Redirect to login and set a redirect url.
125127
StoreRegistry.getStore().dispatch(
126128
logoutAction({
127129
notAuthorised: true,
130+
organizationId,
128131
})
129132
);
130133
return Promise.reject({

client/packages/lowcoder/src/pages/editor/AppEditor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ export default function AppEditor() {
9797
}, [dispatch, applicationId, paramViewMode]);
9898

9999
useEffect(() => {
100+
if (!currentUser?.id) return;
100101
DatasourceApi.fetchJsDatasourceByApp(applicationId).then((res) => {
101102
res.data.data.forEach((i) => {
102103
registryDataSourcePlugin(i.type, i.id, i.pluginDefinition);
103104
});
104105
setIsDataSourcePluginRegistered(true);
105106
});
106107
dispatch(setShowAppSnapshot(false));
107-
}, [applicationId, dispatch]);
108+
}, [applicationId, dispatch, currentUser]);
108109

109110
useEffect(() => {
110111
if (!fetchOrgGroupsFinished) {

client/packages/lowcoder/src/redux/reduxActions/userActions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export const markUserStatus = (type: UserStatusType, value: boolean) => {
5252
};
5353
};
5454

55-
type LogoutActionPayload = { notAuthorised?: boolean };
55+
type LogoutActionPayload = {
56+
notAuthorised?: boolean,
57+
organizationId?: string,
58+
};
5659
export type LogoutActionType = ReduxAction<LogoutActionPayload>;
5760
export const logoutAction = (payload: LogoutActionPayload) => ({
5861
type: ReduxActionTypes.LOGOUT_USER_INIT,

client/packages/lowcoder/src/redux/sagas/userSagas.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
ReduxActionErrorTypes,
77
ReduxActionTypes,
88
} from "constants/reduxActionConstants";
9-
import { AUTH_LOGIN_URL } from "constants/routesURL";
9+
import { AUTH_LOGIN_URL, ORG_AUTH_LOGIN_URL } from "constants/routesURL";
1010
import log from "loglevel";
1111
import { all, call, delay, put, takeLatest } from "redux-saga/effects";
1212
import {
@@ -138,7 +138,9 @@ export function* updateUserSaga(action: ReduxAction<UpdateUserPayload>) {
138138

139139
export function* logoutSaga(action: LogoutActionType) {
140140
try {
141-
let redirectURL = AUTH_LOGIN_URL;
141+
let redirectURL = action.payload.organizationId
142+
? ORG_AUTH_LOGIN_URL.replace(':orgId', action.payload.organizationId)
143+
: AUTH_LOGIN_URL;
142144
if (action.payload.notAuthorised) {
143145
const currentUrl = window.location.href
144146
const urlObj = new URL(currentUrl);

0 commit comments

Comments
 (0)