Skip to content

Commit 64ad399

Browse files
authored
Improve environment variables handling (#99)
1 parent a5b6dca commit 64ad399

File tree

29 files changed

+397
-495
lines changed

29 files changed

+397
-495
lines changed

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ next-env.d.ts
2525
.turbo
2626
.eslintcache
2727

28-
# Environment variables
29-
.env*
30-
!.env.local
31-
!.env.compose
32-
3328
# Logs
3429
*storybook.log
3530
pnpm-debug.log*

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ pnpm docker:prod up -d
264264
- `minimumReleaseAge` - Only install package versions that are at least X minutes old (helps avoid fresh compromised releases).
265265
- `onlyBuiltDependencies` - Only run build/postinstall scripts for this allowlist of dependencies. This reduces the overall attack surface, but scripts for these packages will still run if a compromised version is installed.
266266
- `strictPeerDependencies` - If this is enabled, commands will fail if there is a missing or invalid peer dependency in the tree.
267-
- `peerDependencyRules.allowedVersions` - Allow next-runtime-env to run with Next 15 + React 19. Library declares peer deps for Next 14 / React 18, but works fine with newer versions.
268267
- `strictDepBuilds` - When strictDepBuilds is enabled, the installation will exit with a non-zero exit code if any dependencies have unreviewed build scripts (aka postinstall scripts).
269268
- `engineStrict` - If this is enabled, pnpm will not install any package that claims to not be compatible with the current Node version.
270269
- `catalog` - Catalogs can be used for defining dependency version ranges as reusable constants. Constants defined in catalogs can later be referenced in package.json files.

apps/frontend/.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# NextAuth config
2+
NEXTAUTH_SECRET="aVlrr1mODOkPGrXTt6vN515S8Cry5fnpX5pYFoM/bws="
3+
NEXTAUTH_URL="http://localhost:3000"
4+
5+
# API
6+
API_BASE_URL="http://localhost:3000/api"
7+
8+
# Common
9+
NODE_ENV="development"

apps/frontend/.env.compose

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
########################
2-
## Required variables ##
3-
########################
4-
51
# NextAuth config
62
NEXTAUTH_SECRET="aVlrr1mODOkPGrXTt6vN515S8Cry5fnpX5pYFoM/bws="
3+
NEXTAUTH_URL="http://localhost:3000"
74

8-
########################
9-
## Optional variables ##
10-
########################
11-
12-
# Example environment variables
13-
NEXT_PUBLIC_EXAMPLE_VARIABLE="Public Environment Variable"
14-
PRIVATE_EXAMPLE_VARIABLE="Private Environment Variable XXXXX"
5+
# API
6+
API_BASE_URL="http://localhost:3000/api"
157

168
# Common
179
NODE_ENV="production"

apps/frontend/.env.local

Lines changed: 0 additions & 17 deletions
This file was deleted.

apps/frontend/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
# i18n Messages type augments
22
src/lib/i18n/locales/en/*.d.json.ts
3+
4+
# Environment variables
5+
.env*
6+
!.env
7+
!.env.compose

apps/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"next": "catalog:",
2626
"next-auth": "catalog:",
2727
"next-intl": "catalog:",
28-
"next-runtime-env": "catalog:",
28+
"next-public-env": "1.0.0",
2929
"next-themes": "catalog:",
3030
"postcss": "catalog:",
3131
"react": "catalog:",

apps/frontend/src/app/[locale]/(protected)/_components/HomePage/HomePage.test.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,6 @@ describe('HomePage', () => {
107107
expect(mockGetTranslations).toHaveBeenCalledWith('example.ExamplePage');
108108
});
109109

110-
it('renders the correct link structure', async () => {
111-
mockGetServerSession.mockResolvedValue(null);
112-
113-
const HomePageComponent = await HomePage();
114-
render(HomePageComponent);
115-
116-
const link = screen.getByRole('link');
117-
expect(link).toHaveAttribute('href', '/');
118-
expect(link).toHaveTextContent('This is example page.');
119-
});
120-
121110
it('renders the logo with correct attributes', async () => {
122111
mockGetServerSession.mockResolvedValue(null);
123112

apps/frontend/src/app/[locale]/(protected)/_components/HomePage/HomePage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { getServerSession } from '@/lib/auth';
44
import { ExampleComponent } from '@infinum/ui/components/example';
55
import { getTranslations } from 'next-intl/server';
66
import Image from 'next/image';
7-
import Link from 'next/link';
87

98
export const HomePage = async () => {
109
const t = await getTranslations('example.ExamplePage');
@@ -16,7 +15,7 @@ export const HomePage = async () => {
1615
<Image src="/assets/images/logo.png" alt="Infinum logo" width={180} height={38} priority />
1716
<ExampleComponent className="text-center" text="Welcome to Infinum" />
1817
<h1>{t('title')}</h1>
19-
<Link href="/">{t('about')}</Link>
18+
<p>{t('about')}</p>
2019
<LocaleSwitcher />
2120
<ThemeToggle />
2221
<p className="rainbow:text-green-500 text-blue-600 dark:text-red-500">Colors depend on current variant</p>

apps/frontend/src/app/[locale]/(public)/_components/LoginForm/LoginForm.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,58 @@
11
'use client';
22

3-
import React, { useState } from 'react';
4-
import { signIn } from 'next-auth/react';
5-
import { useRouter } from 'next/navigation';
63
import { Button } from '@infinum/ui/components/button';
7-
import { Label } from '@infinum/ui/components/label';
84
import { Input } from '@infinum/ui/components/input';
5+
import { Label } from '@infinum/ui/components/label';
6+
import { signIn } from 'next-auth/react';
7+
import { useLocale } from 'next-intl';
8+
import React, { useState } from 'react';
99

1010
export const LoginForm = () => {
1111
const [email, setEmail] = useState('');
1212
const [password, setPassword] = useState('');
1313
const [error, setError] = useState('');
14-
const router = useRouter();
14+
const locale = useLocale();
1515

1616
const handleSubmit = async (e: React.FormEvent) => {
1717
e.preventDefault();
1818
setError('');
1919

2020
const res = await signIn('credentials', {
21-
redirect: false,
21+
redirect: true,
2222
email,
2323
password,
24+
callbackUrl: `/${locale}`,
2425
});
2526

2627
if (res?.error) {
2728
setError(res.error);
28-
} else {
29-
router.push('/');
3029
}
3130
};
3231

3332
return (
3433
<form onSubmit={handleSubmit} className="space-y-6">
3534
<div>
3635
<Label htmlFor="email">EMail</Label>
37-
<Input id="email" type="email" value={email} onChange={(e) => setEmail(e.target.value)} required />
36+
<Input
37+
id="email"
38+
type="email"
39+
value={email}
40+
onChange={(e) => setEmail(e.target.value)}
41+
autoComplete="email"
42+
required
43+
/>
3844
</div>
3945

4046
<div>
4147
<Label htmlFor="password">Password</Label>
42-
<Input id="password" type="password" value={password} onChange={(e) => setPassword(e.target.value)} required />
48+
<Input
49+
id="password"
50+
type="password"
51+
value={password}
52+
onChange={(e) => setPassword(e.target.value)}
53+
autoComplete="current-password"
54+
required
55+
/>
4356
</div>
4457

4558
{error && <p className="text-sm text-red-500">{error}</p>}

0 commit comments

Comments
 (0)