Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some login problems #6810

Merged
merged 4 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions frontend/javascripts/admin/admin_rest_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,14 @@ export function sendFailedRequestAnalyticsEvent(
export async function loginUser(formValues: {
email: string;
password: string;
}): Promise<Record<string, any>> {
}): 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<Array<APIUser>> {
Expand Down
5 changes: 3 additions & 2 deletions frontend/javascripts/admin/auth/login_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<string, any>' 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();
Expand Down
5 changes: 3 additions & 2 deletions frontend/javascripts/admin/auth/registration_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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<string, any>' is not assi... Remove this comment to see the full error message
Store.dispatch(setActiveUserAction(user));
Store.dispatch(setActiveOrganizationAction(organization));
}

props.onRegistered(tryAutoLogin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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<string, any>' is not assi... Remove this comment to see the full error message
Store.dispatch(setActiveUserAction(user));
Store.dispatch(setActiveOrganizationAction(organization));
props.onRegistered(true);
}

Expand Down
9 changes: 7 additions & 2 deletions frontend/javascripts/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -265,11 +266,15 @@ class ReactRouter extends React.Component<Props> {
<RouteWithErrorBoundary
path="/dashboard"
render={() => {
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 <DashboardView userId={null} isAdminView={false} initialTabKey={null} />;
}

// Hard navigate
// Hard navigate so that webknossos.org is shown for the demo instance.
window.location.href = "/";
return null;
}}
Expand Down