Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task: fail on startup if SECRET environment variable is missing #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/auth/02-database-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { sessions } from '@/drizzle/schema';
import { db } from '@/drizzle/db';

const secretKey = process.env.SECRET;
if (!secretKey?.length) throw new Error('SECRET environment variable is required');
const key = new TextEncoder().encode(secretKey);

export async function encrypt(payload: SessionPayload) {
Expand Down
2 changes: 2 additions & 0 deletions app/auth/02-stateless-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';

const secretKey = process.env.SECRET;
if (!secretKey?.length) throw new Error('SECRET environment variable is required');
const key = new TextEncoder().encode(secretKey);

export async function encrypt(payload: SessionPayload) {
Expand All @@ -23,6 +24,7 @@ export async function decrypt(session: string | undefined = '') {
});
return payload;
} catch (error) {
console.log('Failed to verify session');
return null;
}
}
Expand Down