Skip to content

Commit aaea1d7

Browse files
committed
Fix reload loop
1 parent 3990061 commit aaea1d7

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

dockerfiles/Dockerfile.development

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ FROM node:${NODE_VERSION}
55

66
LABEL com.iotportaldevicemanagement.product="iotportaldevicemanagement"
77

8+
ARG NEXT_PUBLIC_VERSION=2.0.0
9+
810
ENV NODE_ENV=development
911
ENV NEXT_TELEMETRY_DISABLED=1
12+
ENV NEXT_PUBLIC_VERSION=${NEXT_PUBLIC_VERSION}
13+
14+
# TODO: Implement API from ARG build
15+
#ENV NEXT_PUBLIC_BACKEND_URL=${NEXT_PUBLIC_BACKEND_URL}
1016

1117
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why
1218
# libc6-compat might be needed.

dockerfiles/Dockerfile.production

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ RUN set -eux; \
2121

2222
COPY . .
2323

24+
ARG NEXT_PUBLIC_VERSION=2.0.0
25+
26+
ENV NODE_ENV=production
2427
# Disable telemetry. Learn more here: https://nextjs.org/telemetry
2528
ENV NEXT_TELEMETRY_DISABLED=1
29+
ENV NEXT_PUBLIC_VERSION=${NEXT_PUBLIC_VERSION}
30+
31+
# TODO: Implement API_URL from ARG build
32+
#ENV NEXT_PUBLIC_BACKEND_URL=${NEXT_PUBLIC_BACKEND_URL}
2633

2734
RUN npm run build
2835

@@ -31,8 +38,14 @@ FROM node:${NODE_VERSION} AS runner
3138

3239
LABEL com.iotportaldevicemanagement.product="iotportaldevicemanagement"
3340

41+
ARG NEXT_PUBLIC_VERSION=2.0.0
42+
3443
ENV NODE_ENV=production
3544
ENV NEXT_TELEMETRY_DISABLED=1
45+
ENV NEXT_PUBLIC_VERSION=${NEXT_PUBLIC_VERSION}
46+
47+
# TODO: Implement API_URL from ARG build
48+
#ENV NEXT_PUBLIC_BACKEND_URL=${NEXT_PUBLIC_BACKEND_URL}
3649

3750
WORKDIR /app
3851

src/hooks/useAuth.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export const useAuth = ({ middleware, redirectIfAuthenticated }: UseAuthProps) =
5151
if (error.response.status !== 409)
5252
throw error;
5353

54-
router.push('/verify-email');
54+
if (window.location.pathname !== '/verify-email')
55+
router.push('/verify-email');
5556
})
5657
);
5758

@@ -143,13 +144,22 @@ export const useAuth = ({ middleware, redirectIfAuthenticated }: UseAuthProps) =
143144
.then(() => mutate());
144145
}
145146

146-
window.location.pathname = '/login';
147+
if (window.location.pathname !== '/login')
148+
window.location.pathname = '/login';
147149
};
148150

149151
useEffect(() => {
150-
if (middleware === 'guest' && redirectIfAuthenticated && user) router.push(redirectIfAuthenticated);
151-
if (middleware === 'auth' && redirectIfAuthenticated && user) router.push(redirectIfAuthenticated);
152-
if (middleware === 'auth' && error) logout();
152+
if (
153+
middleware === 'guest' &&
154+
redirectIfAuthenticated &&
155+
user &&
156+
!error &&
157+
window.location.pathname !== redirectIfAuthenticated
158+
)
159+
router.push(redirectIfAuthenticated);
160+
161+
if (middleware === 'auth' && error)
162+
logout();
153163
}, [user, error]);
154164

155165
return {

src/pages/verify-email.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const VerifyEmailPage: NextPageWithLayout = () => {
2020

2121
const { logout, resendEmailVerification } = useAuth({
2222
middleware: 'auth',
23-
redirectIfAuthenticated: '/',
2423
});
2524

2625
return (

0 commit comments

Comments
 (0)