From d6b0155ab494f280fade29485f4aa9eed933b7e1 Mon Sep 17 00:00:00 2001 From: Philipp Otto Date: Fri, 3 Feb 2023 11:31:12 +0100 Subject: [PATCH 1/4] ensure that active organization is set after logging in --- frontend/javascripts/admin/admin_rest_api.ts | 7 +++++-- frontend/javascripts/admin/auth/login_form.tsx | 5 +++-- frontend/javascripts/admin/auth/registration_form.tsx | 5 +++-- .../javascripts/admin/auth/spotlight_registration_form.tsx | 5 +++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/frontend/javascripts/admin/admin_rest_api.ts b/frontend/javascripts/admin/admin_rest_api.ts index 4f53d3866ea..3a2e550933d 100644 --- a/frontend/javascripts/admin/admin_rest_api.ts +++ b/frontend/javascripts/admin/admin_rest_api.ts @@ -142,11 +142,14 @@ export function sendFailedRequestAnalyticsEvent( export async function loginUser(formValues: { email: string; password: string; -}): Promise> { +}): Promise<[APIUser, APIOrganization]> { await Request.sendJSONReceiveJSON("/api/auth/login", { data: formValues, }); - return getActiveUser(); + const activeUser = await getActiveUser(); + const organization = await getOrganization(activeUser.organization); + + return [activeUser, organization]; } export async function getUsers(): Promise> { diff --git a/frontend/javascripts/admin/auth/login_form.tsx b/frontend/javascripts/admin/auth/login_form.tsx index 66a9bcc21fb..248b09f15d7 100644 --- a/frontend/javascripts/admin/auth/login_form.tsx +++ b/frontend/javascripts/admin/auth/login_form.tsx @@ -8,6 +8,7 @@ import { setActiveUserAction } from "oxalis/model/actions/user_actions"; import Store from "oxalis/store"; import messages from "messages"; import features from "features"; +import { setActiveOrganizationAction } from "oxalis/model/actions/organization_actions"; const FormItem = Form.Item; const { Password } = Input; @@ -34,9 +35,9 @@ function LoginForm({ layout, onLoggedIn, hideFooter, style }: Props) { // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'formValues' implicitly has an 'any' typ... Remove this comment to see the full error message const onFinish = async (formValues) => { - const user = await loginUser(formValues); - // @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Record' is not assi... Remove this comment to see the full error message + const [user, organization] = await loginUser(formValues); Store.dispatch(setActiveUserAction(user)); + Store.dispatch(setActiveOrganizationAction(organization)); if (onLoggedIn) { onLoggedIn(); diff --git a/frontend/javascripts/admin/auth/registration_form.tsx b/frontend/javascripts/admin/auth/registration_form.tsx index 4ed10343bd0..34d74449da3 100644 --- a/frontend/javascripts/admin/auth/registration_form.tsx +++ b/frontend/javascripts/admin/auth/registration_form.tsx @@ -8,6 +8,7 @@ import Request from "libs/request"; import Store from "oxalis/throttled_store"; import messages from "messages"; import { setHasOrganizationsAction } from "oxalis/model/actions/ui_actions"; +import { setActiveOrganizationAction } from "oxalis/model/actions/organization_actions"; const FormItem = Form.Item; const { Password } = Input; type Props = { @@ -38,12 +39,12 @@ function RegistrationForm(props: Props) { const tryAutoLogin = props.tryAutoLogin || props.inviteToken != null || autoVerified; if (tryAutoLogin) { - const user = await loginUser({ + const [user, organization] = await loginUser({ email: formValues.email, password: formValues.password.password1, }); - // @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Record' is not assi... Remove this comment to see the full error message Store.dispatch(setActiveUserAction(user)); + Store.dispatch(setActiveOrganizationAction(organization)); } props.onRegistered(tryAutoLogin); diff --git a/frontend/javascripts/admin/auth/spotlight_registration_form.tsx b/frontend/javascripts/admin/auth/spotlight_registration_form.tsx index 5bfd829ee45..164a09339e2 100644 --- a/frontend/javascripts/admin/auth/spotlight_registration_form.tsx +++ b/frontend/javascripts/admin/auth/spotlight_registration_form.tsx @@ -6,6 +6,7 @@ import { setActiveUserAction } from "oxalis/model/actions/user_actions"; import Request from "libs/request"; import Store from "oxalis/throttled_store"; import messages from "messages"; +import { setActiveOrganizationAction } from "oxalis/model/actions/organization_actions"; const FormItem = Form.Item; const { Password } = Input; type Props = { @@ -40,12 +41,12 @@ function SpotlightRegistrationForm(props: Props) { organizationDisplayName: `${formValues.firstName} ${formValues.lastName} Lab`, }, }); - const user = await loginUser({ + const [user, organization] = await loginUser({ email: formValues.email, password: formValues.password.password1, }); - // @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Record' is not assi... Remove this comment to see the full error message Store.dispatch(setActiveUserAction(user)); + Store.dispatch(setActiveOrganizationAction(organization)); props.onRegistered(true); } From ab7830585380cb96e2c5cde94a4d901bf1200152 Mon Sep 17 00:00:00 2001 From: Philipp Otto Date: Fri, 3 Feb 2023 11:31:58 +0100 Subject: [PATCH 2/4] avoid unnecessary page refresh after logging in --- frontend/javascripts/router.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/javascripts/router.tsx b/frontend/javascripts/router.tsx index 6cb75b89f87..899732c776d 100644 --- a/frontend/javascripts/router.tsx +++ b/frontend/javascripts/router.tsx @@ -61,6 +61,7 @@ import { Redirect, Route, Router, Switch } from "react-router-dom"; import { APICompoundTypeEnum, APIUser, TracingTypeEnum } from "types/api_flow_types"; import ErrorBoundary from "components/error_boundary"; +import { Store } from "oxalis/singletons"; const { Content } = Layout; @@ -265,7 +266,11 @@ class ReactRouter extends React.Component { { - if (isAuthenticated) { + // Imperatively access store state to avoid race condition when logging in. + // The `isAuthenticated` prop could be outdated for a short time frame which + // would lead to an unnecessary browser refresh. + const { activeUser } = Store.getState(); + if (activeUser) { return ; } From e6a9ad5dc779fad4a4b41cf87575b52cbaa24ad9 Mon Sep 17 00:00:00 2001 From: Philipp Otto Date: Fri, 3 Feb 2023 11:37:40 +0100 Subject: [PATCH 3/4] update changelog --- CHANGELOG.unreleased.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index da827d31752..a56488fd92b 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -13,9 +13,10 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released ### Added ### Changed -- Limit paid team sharing features to respective organization plans. [6767](https://github.com/scalableminds/webknossos/pull/6776) +- Limit paid team sharing features to respective organization plans. [#6767](https://github.com/scalableminds/webknossos/pull/6776) ### Fixed +- Fixed a benign error message which briefly appeared after logging in. [#6810](https://github.com/scalableminds/webknossos/pull/6810) ### Removed From b558b55277a688eff645d8bde2e85bae267768a4 Mon Sep 17 00:00:00 2001 From: Philipp Otto Date: Fri, 3 Feb 2023 11:47:33 +0100 Subject: [PATCH 4/4] explain hard reload --- frontend/javascripts/router.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/javascripts/router.tsx b/frontend/javascripts/router.tsx index 899732c776d..699b4a1d52b 100644 --- a/frontend/javascripts/router.tsx +++ b/frontend/javascripts/router.tsx @@ -274,7 +274,7 @@ class ReactRouter extends React.Component { return ; } - // Hard navigate + // Hard navigate so that webknossos.org is shown for the demo instance. window.location.href = "/"; return null; }}