Skip to content

Commit 79c07b0

Browse files
on logout, user should redirect to workspace login page when login/register using workspace url
1 parent a43628b commit 79c07b0

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,14 @@ export const apiFailureResponseInterceptor = (error: any) => {
122122
if (!notAuthRequiredPath(error.config?.url)) {
123123
if (error.response.status === API_STATUS_CODES.REQUEST_NOT_AUTHORISED) {
124124
// get x-org-id from failed request
125-
const organizationId = error.response.headers['x-org-id'] || undefined;
125+
let organizationId;
126+
if (error.response.headers['x-org-id']) {
127+
organizationId = error.response.headers['x-org-id'];
128+
}
129+
if (localStorage.getItem('lowcoder_login_orgId')) {
130+
organizationId = localStorage.getItem('lowcoder_login_orgId');
131+
localStorage.removeItem('lowcoder_login_orgId');
132+
}
126133
// Redirect to login and set a redirect url.
127134
StoreRegistry.getStore().dispatch(
128135
logoutAction({

client/packages/lowcoder/src/pages/common/profileDropdown.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ export default function ProfileDropdown(props: DropDownProps) {
150150
dispatch(profileSettingModalVisible(true));
151151
} else if (e.key === "logout") {
152152
// logout
153-
dispatch(logoutAction({}));
153+
const organizationId = localStorage.getItem('lowcoder_login_orgId');
154+
if (organizationId) {
155+
localStorage.removeItem('lowcoder_login_orgId');
156+
}
157+
dispatch(logoutAction({
158+
organizationId: organizationId || undefined,
159+
}));
154160
} else if (e.keyPath.includes("switchOrg")) {
155161
if (e.key === "newOrganization") {
156162
// create new organization

client/packages/lowcoder/src/pages/userAuth/formLoginSteps.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ export default function FormLoginSteps(props: FormLoginProps) {
155155
setSigninEnabled(LOWCODER_EMAIL_AUTH_ENABLED === 'true');
156156
}, [serverSettings]);
157157

158+
const afterLoginSuccess = () => {
159+
if (props.organizationId) {
160+
localStorage.setItem("lowcoder_login_orgId", props.organizationId);
161+
}
162+
fetchUserAfterAuthSuccess?.();
163+
}
164+
158165
const { onSubmit, loading } = useAuthSubmit(
159166
() =>
160167
UserApi.formLogin({
@@ -168,7 +175,7 @@ export default function FormLoginSteps(props: FormLoginProps) {
168175
}),
169176
false,
170177
redirectUrl,
171-
fetchUserAfterAuthSuccess,
178+
afterLoginSuccess,
172179
);
173180

174181
const fetchOrgsByEmail = () => {
@@ -274,7 +281,7 @@ export default function FormLoginSteps(props: FormLoginProps) {
274281
<Divider/>
275282
<AuthBottomView>
276283
<StyledRouteLink to={{
277-
pathname: AUTH_REGISTER_URL,
284+
pathname: props.organizationId ? `/org/${props.organizationId}/auth/register` : AUTH_REGISTER_URL,
278285
state: {...location.state || {}, email: account}
279286
}}>
280287
{trans("userAuth.register")}

client/packages/lowcoder/src/pages/userAuth/register.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ function UserRegister() {
8686
};
8787
}, [serverSettings]);
8888

89+
const afterLoginSuccess = () => {
90+
if (organizationId) {
91+
localStorage.setItem("lowcoder_login_orgId", organizationId);
92+
}
93+
fetchUserAfterAuthSuccess?.();
94+
}
95+
8996
const { loading, onSubmit } = useAuthSubmit(
9097
() =>
9198
UserApi.formLogin({
@@ -99,7 +106,7 @@ function UserRegister() {
99106
}),
100107
false,
101108
redirectUrl,
102-
fetchUserAfterAuthSuccess,
109+
afterLoginSuccess,
103110
);
104111

105112
const checkEmailExist = () => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy