Skip to content

Commit 7a8b631

Browse files
committed
debug(ci): enhance JWT secret and environment variable handling
1 parent 1d99b52 commit 7a8b631

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

apps/collabydraw/next.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { NextConfig } from "next";
2+
import { webpack } from "next/dist/compiled/webpack/webpack";
23

34
const nextConfig: NextConfig = {
45
/* config options here */
@@ -10,6 +11,18 @@ const nextConfig: NextConfig = {
1011
publicRuntimeConfig: {
1112
JWT_SECRET: process.env.JWT_SECRET,
1213
},
14+
15+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
16+
webpack: (config, { isServer }) => {
17+
// Ensure environment variables are always available
18+
config.plugins.push(
19+
new webpack.DefinePlugin({
20+
'process.env.JWT_SECRET': JSON.stringify(process.env.JWT_SECRET),
21+
'process.env.DATABASE_URL': JSON.stringify(process.env.DATABASE_URL),
22+
})
23+
);
24+
return config;
25+
}
1326
};
1427

1528
export default nextConfig;

apps/collabydraw/utils/auth.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ export const authOptions: NextAuthOptions = {
5858
token.id = user.id;
5959
token.email = user.email;
6060
}
61-
61+
if (!process.env.JWT_SECRET) {
62+
throw new Error("JWT_SECRET is ABSOLUTELY REQUIRED and not set");
63+
}
6264
token.accessToken = jwt.sign(
6365
{ id: token.id, email: token.email },
64-
process.env.NEXT_PUBLIC_JWT_SECRET || "",
66+
process.env.JWT_SECRET,
6567
{ expiresIn: "7d" }
6668
);
6769
return token;
@@ -75,5 +77,5 @@ export const authOptions: NextAuthOptions = {
7577
return session;
7678
},
7779
},
78-
secret: process.env.NEXT_PUBLIC_JWT_SECRET,
80+
secret: process.env.JWT_SECRET,
7981
};

docker/Dockerfile.frontend

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ WORKDIR /usr/src/app
99
ARG DATABASE_URL
1010
ARG JWT_SECRET
1111

12-
# Set environment variables
13-
ENV DATABASE_URL=${DATABASE_URL}
14-
ENV JWT_SECRET=${JWT_SECRET}
15-
ENV NEXT_PUBLIC_JWT_SECRET=${JWT_SECRET}
16-
1712
# Copy necessary files for dependency installation
1813
COPY ./packages ./packages
1914
COPY ./package.json ./package.json
@@ -38,6 +33,17 @@ RUN prisma generate
3833
# Change back to the root directory
3934
WORKDIR /usr/src/app
4035

36+
# Set environment variables
37+
ENV DATABASE_URL=${DATABASE_URL}
38+
ENV JWT_SECRET=${JWT_SECRET}
39+
40+
# Debugging step
41+
RUN echo "DATABASE_URL length: ${#DATABASE_URL}"
42+
RUN echo "JWT_SECRET length: ${#JWT_SECRET}"
43+
44+
# Fail if secrets are not set
45+
RUN test -n "$DATABASE_URL" && test -n "$JWT_SECRET"
46+
4147
# Debug step: print environment variables
4248
RUN echo "DATABASE_URL: ${DATABASE_URL}" && echo "JWT_SECRET set: ${JWT_SECRET:+yes}"
4349

0 commit comments

Comments
 (0)