diff --git a/src/app/html/layout.tsx b/src/app/html/layout.tsx
index d94e947..c533d4f 100644
--- a/src/app/html/layout.tsx
+++ b/src/app/html/layout.tsx
@@ -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();
diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx
index f533b67..948e462 100644
--- a/src/components/Layout.tsx
+++ b/src/components/Layout.tsx
@@ -43,6 +43,7 @@ const Wrapper = styled.div`
`;
const publicRoutes = [
+ '/home',
'/login',
'/signup',
'/forgot-password',
@@ -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
@@ -201,7 +202,7 @@ function WithLayoutProvider(props: LayoutPageProps) {
if (!initState) return null;
- if (!userAuth && loading) {
+ if (loading) {
return null;
}
diff --git a/src/components/sidebar/SideBar.tsx b/src/components/sidebar/SideBar.tsx
index 1ff6983..555e28f 100644
--- a/src/components/sidebar/SideBar.tsx
+++ b/src/components/sidebar/SideBar.tsx
@@ -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';
@@ -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;
diff --git a/src/containers/SignIn/SignInFormPassword.tsx b/src/containers/SignIn/SignInFormPassword.tsx
index 96c639b..5386267 100644
--- a/src/containers/SignIn/SignInFormPassword.tsx
+++ b/src/containers/SignIn/SignInFormPassword.tsx
@@ -43,6 +43,7 @@ import {
accessTokenManager,
userCacheManager,
} from '@/lib/storage/deviceStorage';
+import { loginCheck } from '@/lib/utils/auth.utils';
import type { SignInFormProps } from './signin.interface';
@@ -202,7 +203,7 @@ export function SignInFormPassword(props: SignInFormProps) {
}
if (afterLoginRefresh) {
- return reload();
+ return push('/home');
}
return push(afterLogin, {});
@@ -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 (
diff --git a/src/lib/apollo-wrapper.client.tsx b/src/lib/apollo-wrapper.client.tsx
index ad28748..f00f727 100644
--- a/src/lib/apollo-wrapper.client.tsx
+++ b/src/lib/apollo-wrapper.client.tsx
@@ -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';
@@ -215,11 +214,9 @@ export function useApollo(initialState?: ApolloClient) {
* @returns
*/
export function useLogoutSession(): [() => Promise] {
- const { push } = useRouter();
-
const logoutUser = async () => {
await accessTokenManager.delete();
- return push('/login');
+ return window.location.replace('/login');
};
return [logoutUser];
diff --git a/src/lib/config/server.ts b/src/lib/config/server.ts
index 9a9df20..97954c1 100644
--- a/src/lib/config/server.ts
+++ b/src/lib/config/server.ts
@@ -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();