fix: reload page when sign out (#871)

This commit is contained in:
boojack 2022-12-28 20:58:59 +08:00 committed by GitHub
parent 3556ae4e65
commit b6f7a85a2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 18 deletions

View File

@ -54,20 +54,6 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
return nil return nil
}) })
g.POST("/auth/logout", func(c echo.Context) error {
ctx := c.Request().Context()
err := removeUserSession(c)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to set logout session").SetInternal(err)
}
s.Collector.Collect(ctx, &metric.Metric{
Name: "user logout",
})
c.Response().WriteHeader(http.StatusOK)
return nil
})
g.POST("/auth/signup", func(c echo.Context) error { g.POST("/auth/signup", func(c echo.Context) error {
ctx := c.Request().Context() ctx := c.Request().Context()
signup := &api.Signup{} signup := &api.Signup{}
@ -143,4 +129,17 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
} }
return nil return nil
}) })
g.POST("/auth/logout", func(c echo.Context) error {
ctx := c.Request().Context()
err := removeUserSession(c)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to set logout session").SetInternal(err)
}
s.Collector.Collect(ctx, &metric.Metric{
Name: "user logout",
})
return c.JSON(http.StatusOK, true)
})
} }

View File

@ -1,6 +1,5 @@
import { useCallback, useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { useLocationStore, useMemoStore, useTagStore, useUserStore } from "../store/module"; import { useLocationStore, useMemoStore, useTagStore, useUserStore } from "../store/module";
import { getMemoStats } from "../helpers/api"; import { getMemoStats } from "../helpers/api";
import * as utils from "../helpers/utils"; import * as utils from "../helpers/utils";
@ -13,7 +12,6 @@ import "../less/user-banner.less";
const UserBanner = () => { const UserBanner = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const navigate = useNavigate();
const locationStore = useLocationStore(); const locationStore = useLocationStore();
const userStore = useUserStore(); const userStore = useUserStore();
const memoStore = useMemoStore(); const memoStore = useMemoStore();
@ -66,7 +64,8 @@ const UserBanner = () => {
}; };
const handleSignOutBtnClick = async () => { const handleSignOutBtnClick = async () => {
navigate("/auth"); await userStore.doSignOut();
window.location.href = "/auth";
}; };
return ( return (

View File

@ -92,7 +92,6 @@ const doSignIn = async () => {
}; };
const doSignOut = async () => { const doSignOut = async () => {
store.dispatch(setUser());
await api.signout(); await api.signout();
}; };