Skip to content

Commit

Permalink
🐛 fix: login button not show on user panel (lobehub#2496)
Browse files Browse the repository at this point in the history
* 🐛 fix: show login button when enable nextauth

* 🐛 fix: wrong navigate after logout
  • Loading branch information
cy948 authored May 14, 2024
1 parent 1484a04 commit 39637fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/features/User/UserPanel/PanelContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Flexbox } from 'react-layout-kit';

import BrandWatermark from '@/components/BrandWatermark';
import Menu from '@/components/Menu';
import { enableAuth } from '@/const/auth';
import { useUserStore } from '@/store/user';
import { authSelectors } from '@/store/user/selectors';

Expand All @@ -18,10 +17,12 @@ import { useMenu } from './useMenu';
const PanelContent = memo<{ closePopover: () => void }>(({ closePopover }) => {
const router = useRouter();
const isLoginWithAuth = useUserStore(authSelectors.isLoginWithAuth);
const [openSignIn, signOut, openUserProfile] = useUserStore((s) => [
const [openSignIn, signOut, openUserProfile, enableAuth, enabledNextAuth] = useUserStore((s) => [
s.openLogin,
s.logout,
s.openUserProfile,
s.enableAuth(),
s.enabledNextAuth(),
]);
const { mainItems, logoutItems } = useMenu();

Expand All @@ -39,6 +40,8 @@ const PanelContent = memo<{ closePopover: () => void }>(({ closePopover }) => {
const handleSignOut = () => {
signOut();
closePopover();
// NextAuth doesn't need to redirect to login page
if (enabledNextAuth) return;
router.push('/login');
};

Expand Down
9 changes: 3 additions & 6 deletions src/features/User/__tests__/PanelContent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ vi.mock('../DataStatistics', () => ({
// 定义一个变量来存储 enableAuth 的值
let enableAuth = true;

// 模拟 @/const/auth 模块
vi.mock('@/const/auth', () => ({
get enableAuth() {
return enableAuth;
},
}));
beforeEach(() => {
useUserStore.setState({ enableAuth: () => true });
});

afterEach(() => {
enableAuth = true;
Expand Down

0 comments on commit 39637fb

Please sign in to comment.