mirror of
https://github.com/umami-software/umami.git
synced 2026-02-13 09:05:36 +01:00
Replaced redux with zustand. Fixed login issue, closes #980.
This commit is contained in:
parent
7071f5fba5
commit
9937caa569
33 changed files with 234 additions and 286 deletions
|
|
@ -2,8 +2,6 @@ import React from 'react';
|
|||
import Head from 'next/head';
|
||||
import { useRouter } from 'next/router';
|
||||
import { IntlProvider } from 'react-intl';
|
||||
import { Provider } from 'react-redux';
|
||||
import { useStore } from 'redux/store';
|
||||
import useLocale from 'hooks/useLocale';
|
||||
import 'styles/variables.css';
|
||||
import 'styles/bootstrap-grid.css';
|
||||
|
|
@ -24,11 +22,10 @@ const Intl = ({ children }) => {
|
|||
};
|
||||
|
||||
export default function App({ Component, pageProps }) {
|
||||
const store = useStore();
|
||||
const { basePath } = useRouter();
|
||||
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<Intl>
|
||||
<Head>
|
||||
<link rel="icon" href={`${basePath}/favicon.ico`} />
|
||||
<link rel="apple-touch-icon" sizes="180x180" href={`${basePath}/apple-touch-icon.png`} />
|
||||
|
|
@ -41,9 +38,7 @@ export default function App({ Component, pageProps }) {
|
|||
<meta name="theme-color" content="#2f2f2f" media="(prefers-color-scheme: dark)" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
</Head>
|
||||
<Intl>
|
||||
<Component {...pageProps} />
|
||||
</Intl>
|
||||
</Provider>
|
||||
<Component {...pageProps} />
|
||||
</Intl>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,10 @@ export default async (req, res) => {
|
|||
|
||||
if (account && (await checkPassword(password, account.password))) {
|
||||
const { user_id, username, is_admin } = account;
|
||||
const token = await createSecureToken({ user_id, username, is_admin });
|
||||
const user = { user_id, username, is_admin };
|
||||
const token = await createSecureToken(user);
|
||||
|
||||
return ok(res, { token });
|
||||
return ok(res, { token, user });
|
||||
}
|
||||
|
||||
return unauthorized(res);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import { useEffect } from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { useRouter } from 'next/router';
|
||||
import { get } from 'lib/web';
|
||||
import { updateUser } from 'redux/actions/user';
|
||||
import { removeItem } from 'lib/web';
|
||||
import { AUTH_TOKEN } from 'lib/constants';
|
||||
import { setUser } from 'store/app';
|
||||
|
||||
export default function LogoutPage() {
|
||||
const dispatch = useDispatch();
|
||||
const router = useRouter();
|
||||
const { basePath } = router;
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(updateUser(null));
|
||||
get(`${basePath}/api/auth/logout`).then(() => router.push('/login'));
|
||||
removeItem(AUTH_TOKEN);
|
||||
router.push('/login');
|
||||
|
||||
return () => setUser(null);
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue