Commit 9cc3d536 authored by tom's avatar tom

add logout

parent b4072735
...@@ -28,12 +28,16 @@ export function get(name?: NAMES | undefined | null, serverCookie?: string) { ...@@ -28,12 +28,16 @@ export function get(name?: NAMES | undefined | null, serverCookie?: string) {
} }
} }
export function set(name: string, value: string, attributes: Cookies.CookieAttributes = {}) { export function set(name: NAMES, value: string, attributes: Cookies.CookieAttributes = {}) {
attributes.path = '/'; attributes.path = '/';
return Cookies.set(name, value, attributes); return Cookies.set(name, value, attributes);
} }
export function remove(name: NAMES, attributes: Cookies.CookieAttributes = {}) {
return Cookies.remove(name, attributes);
}
export function getFromCookieString(cookieString: string, name?: NAMES | undefined | null) { export function getFromCookieString(cookieString: string, name?: NAMES | undefined | null) {
return cookieString.split(`${ name }=`)[1]?.split(';')[0]; return cookieString.split(`${ name }=`)[1]?.split(';')[0];
} }
...@@ -3,7 +3,7 @@ import React from 'react'; ...@@ -3,7 +3,7 @@ import React from 'react';
import type { Screen } from '../types'; import type { Screen } from '../types';
import useSignInWithWallet from './useSignInWithWallet'; import useSignInWithWallet from '../useSignInWithWallet';
interface Props { interface Props {
onSuccess: (screen: Screen) => void; onSuccess: (screen: Screen) => void;
......
import { useRouter } from 'next/router';
import React from 'react';
import type { Route } from 'nextjs-routes';
import * as cookies from 'lib/cookies';
const PROTECTED_ROUTES: Array<Route['pathname']> = [
'/account/api-key',
'/account/custom-abi',
'/account/tag-address',
'/account/verified-addresses',
'/account/watchlist',
'/auth/profile',
'/auth/unverified-email',
];
export default function useLogout() {
const router = useRouter();
return React.useCallback(async() => {
cookies.remove(cookies.NAMES.API_TOKEN);
if (
PROTECTED_ROUTES.includes(router.pathname) ||
(router.pathname === '/txs' && router.query.tab === 'watchlist')
) {
window.location.assign('/');
} else {
window.location.reload();
}
}, [ router ]);
}
import type { ButtonProps } from '@chakra-ui/react'; import type { ButtonProps } from '@chakra-ui/react';
import { Button, Skeleton, Tooltip, Text, HStack } from '@chakra-ui/react'; import { Button, Skeleton, Tooltip, Box, HStack } from '@chakra-ui/react';
import type { UseQueryResult } from '@tanstack/react-query'; import type { UseQueryResult } from '@tanstack/react-query';
import React from 'react'; import React from 'react';
...@@ -55,7 +55,7 @@ const ProfileButton = ({ profileQuery, size, variant, onClick, isPending }: Prop ...@@ -55,7 +55,7 @@ const ProfileButton = ({ profileQuery, size, variant, onClick, isPending }: Prop
return ( return (
<HStack gap={ 2 }> <HStack gap={ 2 }>
<ProfileAddressIcon address={ address } isAutoConnectDisabled={ isAutoConnectDisabled }/> <ProfileAddressIcon address={ address } isAutoConnectDisabled={ isAutoConnectDisabled }/>
<Text display={{ base: 'none', md: 'block' }}>{ text }</Text> <Box display={{ base: 'none', md: 'block' }}>{ text }</Box>
</HStack> </HStack>
); );
} }
...@@ -64,7 +64,7 @@ const ProfileButton = ({ profileQuery, size, variant, onClick, isPending }: Prop ...@@ -64,7 +64,7 @@ const ProfileButton = ({ profileQuery, size, variant, onClick, isPending }: Prop
return ( return (
<HStack gap={ 2 }> <HStack gap={ 2 }>
<IconSvg name="profile" boxSize={ 5 }/> <IconSvg name="profile" boxSize={ 5 }/>
<Text display={{ base: 'none', md: 'block' }}>{ getUserHandle(data.email) }</Text> <Box display={{ base: 'none', md: 'block' }}>{ getUserHandle(data.email) }</Box>
</HStack> </HStack>
); );
} }
......
...@@ -5,7 +5,7 @@ import React from 'react'; ...@@ -5,7 +5,7 @@ import React from 'react';
import useFetchProfileInfo from 'lib/hooks/useFetchProfileInfo'; import useFetchProfileInfo from 'lib/hooks/useFetchProfileInfo';
import Popover from 'ui/shared/chakra/Popover'; import Popover from 'ui/shared/chakra/Popover';
import AuthModal from 'ui/snippets/auth/AuthModal'; import AuthModal from 'ui/snippets/auth/AuthModal';
import useSignInWithWallet from 'ui/snippets/auth/screens/useSignInWithWallet'; import useSignInWithWallet from 'ui/snippets/auth/useSignInWithWallet';
import ProfileButton from './ProfileButton'; import ProfileButton from './ProfileButton';
import ProfileMenuContent from './ProfileMenuContent'; import ProfileMenuContent from './ProfileMenuContent';
......
...@@ -9,6 +9,7 @@ import { route } from 'nextjs-routes'; ...@@ -9,6 +9,7 @@ import { route } from 'nextjs-routes';
import config from 'configs/app'; import config from 'configs/app';
import { useMarketplaceContext } from 'lib/contexts/marketplace'; import { useMarketplaceContext } from 'lib/contexts/marketplace';
import IconSvg from 'ui/shared/IconSvg'; import IconSvg from 'ui/shared/IconSvg';
import useLogout from 'ui/snippets/auth/useLogout';
import ProfileMenuNavLink from './ProfileMenuNavLink'; import ProfileMenuNavLink from './ProfileMenuNavLink';
import ProfileMenuWallet from './ProfileMenuWallet'; import ProfileMenuWallet from './ProfileMenuWallet';
...@@ -50,6 +51,7 @@ interface Props { ...@@ -50,6 +51,7 @@ interface Props {
const ProfileMenuContent = ({ data, onClose }: Props) => { const ProfileMenuContent = ({ data, onClose }: Props) => {
const { isAutoConnectDisabled } = useMarketplaceContext(); const { isAutoConnectDisabled } = useMarketplaceContext();
const alertBgColor = useColorModeValue('orange.100', 'orange.900'); const alertBgColor = useColorModeValue('orange.100', 'orange.900');
const logout = useLogout();
return ( return (
<Box> <Box>
...@@ -101,7 +103,7 @@ const ProfileMenuContent = ({ data, onClose }: Props) => { ...@@ -101,7 +103,7 @@ const ProfileMenuContent = ({ data, onClose }: Props) => {
<ProfileMenuNavLink <ProfileMenuNavLink
text="Sign out" text="Sign out"
icon="sign_out" icon="sign_out"
onClick={ onClose } onClick={ logout }
/> />
</Box> </Box>
); );
......
...@@ -4,8 +4,8 @@ import React from 'react'; ...@@ -4,8 +4,8 @@ import React from 'react';
import useFetchProfileInfo from 'lib/hooks/useFetchProfileInfo'; import useFetchProfileInfo from 'lib/hooks/useFetchProfileInfo';
import AuthModal from 'ui/snippets/auth/AuthModal'; import AuthModal from 'ui/snippets/auth/AuthModal';
import useSignInWithWallet from 'ui/snippets/auth/useSignInWithWallet';
import useSignInWithWallet from '../auth/screens/useSignInWithWallet';
import ProfileButton from './ProfileButton'; import ProfileButton from './ProfileButton';
import ProfileMenuContent from './ProfileMenuContent'; import ProfileMenuContent from './ProfileMenuContent';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment