Skip to content

Commit

Permalink
fix(ui): config, signin
Browse files Browse the repository at this point in the history
  • Loading branch information
ceddybi committed Apr 15, 2024
1 parent ba483a0 commit 106dbde
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/app/html/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default async function HtmlLayout({
const isIndex = pathname === '/html';

if (!loginRequired) {
publicRoutes.push('/html/ad/', '/html/store/');
publicRoutes.push('/html/ad/', '/html/store/', '/html/u/');
}

user = await getMe();
Expand Down
7 changes: 4 additions & 3 deletions src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const Wrapper = styled.div`
`;

const publicRoutes = [
'/home',
'/login',
'/signup',
'/forgot-password',
Expand All @@ -61,12 +62,12 @@ function LayoutPage({ children, ...props }: LayoutPageProps) {

const pathname = usePathname();

const loginRequired = getConfig().REQUIRE_LOGIN || auth;
const loginRequired = !!getConfig().REQUIRE_LOGIN || auth;

const isIndex = pathname === '/';

if (!loginRequired) {
publicRoutes.push('/ad/', '/store/');
publicRoutes.push('/ad/', '/store/', '/u/');
}

// isVendor
Expand Down Expand Up @@ -201,7 +202,7 @@ function WithLayoutProvider(props: LayoutPageProps) {

if (!initState) return null;

if (!userAuth && loading) {
if (loading) {
return null;
}

Expand Down
7 changes: 5 additions & 2 deletions src/components/sidebar/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import isEmpty from 'lodash/isEmpty';
import { usePathname, useRouter } from 'next/navigation';
import * as React from 'react';

import { APPEVENTS } from '@/lib/AppEvent';
import useEvent from '@/lib/hooks/useEvent';
import { useMeApi, useVendor } from '@/lib/hooks/useUserCache';

import { adminMenus, adsStoreMenus, clientMenus } from './menus';
Expand Down Expand Up @@ -58,8 +60,9 @@ export const VerticalSideBar = ({
// menus: client ? clientMenus : adminMenus,
});

// TODO auth
const user = useMeApi();
const userApi = useMeApi();
const userAccessToken = useEvent(APPEVENTS.AUTH);
const user = userApi || userAccessToken?.user;
const isAdmin = user?.admin || false;
const { vendor } = useVendor();
const { open } = state;
Expand Down
19 changes: 10 additions & 9 deletions src/containers/SignIn/SignInFormPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
accessTokenManager,
userCacheManager,
} from '@/lib/storage/deviceStorage';
import { loginCheck } from '@/lib/utils/auth.utils';

import type { SignInFormProps } from './signin.interface';

Expand Down Expand Up @@ -202,7 +203,7 @@ export function SignInFormPassword(props: SignInFormProps) {
}

if (afterLoginRefresh) {
return reload();
return push('/home');
}

return push(afterLogin, {});
Expand Down Expand Up @@ -346,14 +347,14 @@ export function SignInFormPassword(props: SignInFormProps) {
};

// TODO re-ADD Initial check if user is not loggedIn
// React.useEffect(() => {
// (async () => {
// const isLoggedIn = await loginCheck();
// if (isLoggedIn) {
// return await push(SCREENS.Home);
// }
// })();
// }, []);
React.useEffect(() => {
(async () => {
const isLoggedIn = await loginCheck();
if (isLoggedIn) {
return push('/home');
}
})();
}, []);

const MnemonicKey = () => {
return (
Expand Down
5 changes: 1 addition & 4 deletions src/lib/apollo-wrapper.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
SSRMultipartLink,
} from '@apollo/experimental-nextjs-app-support/ssr';
import includes from 'lodash/includes';
import { useRouter } from 'next/navigation';
import omitDeep from 'omit-deep';
import { useEffect, useMemo } from 'react';
import { setVerbosity } from 'ts-invariant';
Expand Down Expand Up @@ -215,11 +214,9 @@ export function useApollo(initialState?: ApolloClient<any>) {
* @returns
*/
export function useLogoutSession(): [() => Promise<void>] {
const { push } = useRouter();

const logoutUser = async () => {
await accessTokenManager.delete();
return push('/login');
return window.location.replace('/login');
};

return [logoutUser];
Expand Down
3 changes: 2 additions & 1 deletion src/lib/config/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { getSiteSettings } from '@/lib/hooksServer/settings';

export const fetchConfig = async () => {
const config = getConfig();
if (!isEmpty(config)) {
const isNodeJs = process.env.NEXT_RUNTIME === 'nodejs';
if (!isEmpty(config) && !isNodeJs) {
return config;
}
const siteSettings = await getSiteSettings();
Expand Down

0 comments on commit 106dbde

Please sign in to comment.