Skip to content

Commit 5043c4f

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

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ ARG JWT_SECRET
1212
# Set environment variables
1313
ENV DATABASE_URL=${DATABASE_URL}
1414
ENV JWT_SECRET=${JWT_SECRET}
15-
ENV NEXT_PUBLIC_JWT_SECRET=${JWT_SECRET}
15+
16+
# Debugging step
17+
RUN echo "DATABASE_URL length: ${#DATABASE_URL}"
18+
RUN echo "JWT_SECRET length: ${#JWT_SECRET}"
19+
20+
# Fail if secrets are not set
21+
RUN test -n "$DATABASE_URL" && test -n "$JWT_SECRET"
1622

1723
# Copy necessary files for dependency installation
1824
COPY ./packages ./packages

0 commit comments

Comments
 (0)