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

make logout from settings modal functional #241

Closed
Closed
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
8 changes: 8 additions & 0 deletions components/app/interface/settings/client/Logout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Navigate } from "../../../../routing/index";

/**
* redirect to login page after logout
*/
export default function Logout() {
return <Navigate href="/login" />;
}
10 changes: 10 additions & 0 deletions components/app/interface/settings/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import bots from "./Bots";
import experiments from "./Experiments";
import feedback from "./Feedback";
import language from "./Language";
import logout from "./Logout";
import native from "./Native";
import notifications from "./Notifications";
import sessions from "./Sessions";
Expand Down Expand Up @@ -196,6 +197,14 @@ const Config: SettingsConfiguration<{ server: Server }> = {
{
id: "logout",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit id, only onClick is necessary.

icon: <BiSolidExit size={20} color={theme!.colours.error} />,
href: "/login",
onClick: () => {
const acli = getController("state");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package should also have direct access to state and it can be called through state.

const cli = getController("client").getCurrentClient();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client is available through context here, add const client = useClient() at the top of the function instead of using this line here.

console.log(cli);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous print statement

acli.auth.removeSession(cli?.user?.id as string);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will remove the session from storage but not kill the active client in the client controller, which is remedied by assigning window.location.href (since that will just kill all active sessions) but we want to avoid reloading the client.

window.location.href = "/login";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should useNavigate from routing package at top of component, and then use navigate function instead of telling the browser to redirect us.

},
title: (
<ColouredText colour={theme!.colours.error}>
{t("app.settings.pages.logOut")}
Expand Down Expand Up @@ -227,4 +236,5 @@ const ClientSettingsRouting: Record<string, Component> = {
sync,
native,
experiments,
logout,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once id is omitted, this component no longer needs to be included.

};
Loading