Compare commits

...

20 commits

Author SHA1 Message Date
295c36f6e6
fix: listen on 127.0.0.1
Some checks failed
container-scan / Container Scan (pull_request) Failing after 1m35s
tests / Tests (pull_request) Failing after 1m6s
docker-build / docker (pull_request) Failing after 6m19s
2025-05-13 23:58:54 +02:00
701f900c2d
fix(tests): start server for e2e tests 2025-05-13 23:58:53 +02:00
4fcb5ef968
chore(ci): improve docker cleanup 2025-05-13 23:58:52 +02:00
887e9dd812
chore(ci): run e2e tests in workflow 2025-05-13 23:58:51 +02:00
c8a5ad1b9c
chore(ci): docker cleanup 2025-05-13 23:58:50 +02:00
69ea057f05
test(e2e): test login page 2025-05-13 23:58:49 +02:00
af28f8e7f1
chore: add testing workflow 2025-05-13 23:56:51 +02:00
b41ca153da
test: theme-picker 2025-05-13 23:56:50 +02:00
0056138a01
test: icon-button 2025-05-13 23:56:49 +02:00
8d50447cf1
test: helper functions 2025-05-13 23:56:48 +02:00
9c87a93176
test: initialize cypress e2e testing library 2025-05-13 23:56:47 +02:00
8fd93fa7bc Merge pull request 'refactor: auth flow, middleware and login page' (#55)
All checks were successful
container-scan / Container Scan (push) Successful in 2m3s
docker-build / docker (push) Successful in 3m41s
Reviewed-on: #55
Reviewed-by: Maximilian Liebmann <lima@noreply.git.dominikstahl.dev>
2025-05-13 18:34:58 +00:00
aca229b3d3 refactor: removes unused sso logout button 2025-05-13 18:34:58 +00:00
4f974a0b70 docs: test user for development 2025-05-13 18:34:58 +00:00
b68a561886 feat: add logout page 2025-05-13 18:34:58 +00:00
20eb6ae04a refactor: dynamically generated login page 2025-05-13 18:34:58 +00:00
ddcb14e564 refactor: move auth check into pages 2025-05-13 18:34:58 +00:00
dd6b82515e chore(deps): update dependency @types/react-dom to v19.1.5
All checks were successful
container-scan / Container Scan (push) Successful in 1m51s
docker-build / docker (push) Successful in 1m54s
2025-05-13 11:00:46 +00:00
f79b7b78f9 Merge pull request 'chore(deps): update dependency @types/react to v19.1.4' (#57)
All checks were successful
container-scan / Container Scan (push) Successful in 1m21s
docker-build / docker (push) Successful in 1m4s
Reviewed-on: #57
Reviewed-by: Dominik <mail@dominikstahl.dev>
2025-05-12 21:10:15 +00:00
fc828b2ac5 chore(deps): update dependency @types/react to v19.1.4
All checks were successful
container-scan / Container Scan (pull_request) Successful in 2m26s
docker-build / docker (pull_request) Successful in 3m5s
docker-build / docker (push) Successful in 4m20s
2025-05-12 20:00:50 +00:00
30 changed files with 1707 additions and 151 deletions

View file

@ -7,5 +7,3 @@ AUTH_AUTHENTIK_SECRET=
AUTH_AUTHENTIK_ISSUER=
NEXT_PUBLIC_APP_URL=
MEETUP_SKIP_LOGIN=

5
.env.test Normal file
View file

@ -0,0 +1,5 @@
AUTH_SECRET="auth_secret"
AUTH_URL="http://127.0.0.1:3000"
HOSTNAME="127.0.0.1"
DATABASE_URL="file:./dev.db"
AUTH_AUTHENTIK_ISSUER="auth_issuer"

View file

@ -32,6 +32,7 @@ jobs:
path: trivy-report.json
- name: Clean up Docker
if: always()
run: |
docker buildx prune --filter=until=48h -f
docker image rm meetup_trivy
docker system prune -af --filter "until=24h"
docker volume prune -f

View file

@ -65,5 +65,7 @@ jobs:
cache-to: type=registry,ref=git.dominikstahl.dev/${{ env.REPO }}:buildcache,mode=max
- name: Clean up Docker
if: always()
run: |
docker buildx prune --filter=until=48h -f
docker system prune -af --filter "until=24h"
docker volume prune -f

35
.github/workflows/tests.yml vendored Normal file
View file

@ -0,0 +1,35 @@
name: tests
on:
push:
branches:
- main
- renovate/*
pull_request:
jobs:
tests:
name: Tests
runs-on: docker
container:
image: cypress/browsers:latest
options: --user 1001
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Enable corepack
run: corepack enable
- name: Cypress run (e2e)
uses: https://github.com/cypress-io/github-action@v6
with:
build: yarn cypress:build
start: yarn cypress:start_server
e2e: true
wait-on: 'http://127.0.0.1:3000'
- name: Cypress run (component)
uses: https://github.com/cypress-io/github-action@v6
with:
build: yarn cypress:build
start: yarn cypress:start_server
component: true

6
.gitignore vendored
View file

@ -33,6 +33,7 @@ yarn-error.log*
# env files (can opt-in for committing if needed)
.env*
!.env.example
!.env.test
# vercel
.vercel
@ -40,3 +41,8 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
# cypress
cypress/videos
cypress/screenshots
cypress/coverage

View file

@ -94,10 +94,6 @@ This project is built with a modern tech stack:
# Base URL of your application
NEXT_PUBLIC_APP_URL="http://localhost:3000"
# Development: Skip login flow (set to "true" to bypass authentication)
# Ensure this is NOT set to "true" in production.
MEETUP_SKIP_LOGIN="false"
```
4. **Apply database migrations (Prisma):**
@ -111,11 +107,20 @@ This project is built with a modern tech stack:
- (Optional: If you need to generate Prisma Client without running migrations, use `npx prisma generate`)
5. **Run the development server:**
```bash
yarn dev
```
Open [http://localhost:3000](http://localhost:3000) in your browser to see the application.
The test user for the application is:
```bash
email: test@example.com
password: password
```
**Self-Hosting with Docker (Planned):**
- A Docker image and `docker-compose.yml` file will be provided in the future to allow for easy self-hosting of the MeetUP application. This setup will also include database services. Instructions will be updated here once available.

16
cypress.config.ts Normal file
View file

@ -0,0 +1,16 @@
import { defineConfig } from 'cypress';
export default defineConfig({
component: {
devServer: {
framework: 'next',
bundler: 'webpack',
},
},
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});

31
cypress/e2e/login.cy.ts Normal file
View file

@ -0,0 +1,31 @@
describe('login', () => {
it('loads', () => {
cy.visit('http://127.0.0.1:3000/');
cy.getBySel('login-header').should('exist');
});
it('shows login form', () => {
cy.visit('http://127.0.0.1:3000/');
cy.getBySel('login-form').should('exist');
cy.getBySel('email-input').should('exist');
cy.getBySel('password-input').should('exist');
cy.getBySel('login-button').should('exist');
});
it('shows sso button', () => {
cy.visit('http://127.0.0.1:3000/');
cy.getBySel('sso-login-button_authentik').should('exist');
});
it('allows login', () => {
cy.visit('http://127.0.0.1:3000/');
cy.getBySel('email-input').type('test@example.com');
cy.getBySel('password-input').type('password');
cy.getBySel('login-button').click();
cy.url().should('include', '/home');
});
});

View file

@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}

View file

@ -0,0 +1,62 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
Cypress.Commands.add('getBySel', (selector, ...args) => {
return cy.get(`[data-cy=${selector}]`, ...args);
});
Cypress.Commands.add('getBySelLike', (selector, ...args) => {
return cy.get(`[data-cy*=${selector}]`, ...args);
});
declare global {
namespace Cypress {
interface Chainable {
getBySel(
selector: string,
...args: any[]
): Chainable<JQuery<HTMLElement>>;
getBySelLike(
selector: string,
...args: any[]
): Chainable<JQuery<HTMLElement>>;
}
}
}
export {};

View file

@ -0,0 +1,14 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Components App</title>
<!-- Used by Next.js to inject CSS. -->
<div id="__next_css__DO_NOT_USE__"></div>
</head>
<body>
<div data-cy-root></div>
</body>
</html>

View file

@ -0,0 +1,38 @@
// ***********************************************************
// This example support/component.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
import '@/app/globals.css';
// Import commands.js using ES2015 syntax:
import './commands';
import { mount } from 'cypress/react';
// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare global {
namespace Cypress {
interface Chainable {
mount: typeof mount;
}
}
}
Cypress.Commands.add('mount', mount);
// Example use:
// cy.mount(<MyComponent />)

17
cypress/support/e2e.ts Normal file
View file

@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands';

View file

@ -5,9 +5,13 @@
"scripts": {
"dev": "next dev --turbopack",
"build": "prettier --check . && next build",
"start": "next start",
"start": "node .next/standalone/server.js",
"lint": "next lint",
"format": "prettier --write ."
"format": "prettier --write .",
"cypress:build": "prettier --check . && NODE_ENV=test next build",
"cypress:start_server": "cp .env.test .next/standalone && cp public .next/standalone/ -r && cp .next/static/ .next/standalone/.next/ -r && NODE_ENV=test HOSTNAME=\"0.0.0.0\" dotenv -e .env.test -- node .next/standalone/server.js",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.7.2",
@ -38,8 +42,10 @@
"@eslint/eslintrc": "3.3.1",
"@tailwindcss/postcss": "4.1.6",
"@types/node": "22.15.17",
"@types/react": "19.1.3",
"@types/react-dom": "19.1.4",
"@types/react": "19.1.4",
"@types/react-dom": "19.1.5",
"cypress": "14.3.3",
"dotenv-cli": "^8.0.0",
"eslint": "9.26.0",
"eslint-config-next": "15.3.2",
"eslint-config-prettier": "10.1.5",

View file

@ -1,4 +1,3 @@
import { Logout } from '@/components/user/sso-logout-button';
import { RedirectButton } from '@/components/user/redirect-button';
import { ThemePicker } from '@/components/user/theme-picker';
@ -8,7 +7,7 @@ export default function Home() {
<div className='absolute top-4 right-4'>{<ThemePicker />}</div>
<div>
<h1>Home</h1>
<Logout />
<RedirectButton redirectUrl='/logout' buttonText='Logout' />
<RedirectButton redirectUrl='/settings' buttonText='Settings' />
</div>
</div>

View file

@ -1,4 +1,4 @@
import { auth } from '@/auth';
import { auth, providerMap } from '@/auth';
import SSOLogin from '@/components/user/sso-login-button';
import LoginForm from '@/components/user/login-form';
import { redirect } from 'next/navigation';
@ -30,16 +30,23 @@ export default async function LoginPage() {
<div>
<Card className='w-[350px] max-w-screen'>
<CardHeader>
<CardTitle className='text-lg text-center'>Login</CardTitle>
<CardTitle className='text-lg text-center' data-cy='login-header'>
Login
</CardTitle>
</CardHeader>
<CardContent className='gap-6 flex flex-col'>
<LoginForm />
<hr />
{providerMap.length > 0 && <hr />}
{process.env.AUTH_AUTHENTIK_ISSUER && (
<SSOLogin provider='authentik' providerDisplayName='SSO' />
)}
{providerMap.map((provider) => (
<SSOLogin
key={provider.id}
provider={provider.id}
providerDisplayName={provider.name}
data-cy={'sso-login-button_' + provider.name.toLowerCase()}
/>
))}
</CardContent>
</Card>
</div>

40
src/app/logout/page.tsx Normal file
View file

@ -0,0 +1,40 @@
import { signOut } from '@/auth';
import { Button } from '@/components/ui/button';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card';
export default function SignOutPage() {
return (
<div className='flex flex-col items-center justify-center h-screen'>
<form
action={async () => {
'use server';
await signOut({ redirectTo: '/login' });
}}
>
<Card className='w-[350px] max-w-screen'>
<CardHeader>
<CardTitle className='text-lg text-center'>Logout</CardTitle>
<CardDescription className='text-center'>
Are you sure you want to log out?
</CardDescription>
</CardHeader>
<CardContent className='gap-6 flex flex-col'>
<Button
className='hover:bg-blue-600 hover:text-white'
type='submit'
variant='secondary'
>
Logout
</Button>
</CardContent>
</Card>
</form>
</div>
);
}

View file

@ -1,3 +1,9 @@
export default function Home() {
return <div></div>;
import { auth } from '@/auth';
import { redirect } from 'next/navigation';
export default async function Home() {
const session = await auth();
if (!session?.user) redirect('/login');
else redirect('/home');
}

View file

@ -1,13 +1,49 @@
import NextAuth from 'next-auth';
import type { Provider } from 'next-auth/providers';
import Credentials from 'next-auth/providers/credentials';
import Authentik from 'next-auth/providers/authentik';
const providers: Provider[] = [
!process.env.DISABLE_PASSWORD_LOGIN &&
Credentials({
credentials: { password: { label: 'Password', type: 'password' } },
authorize(c) {
if (c.password !== 'password') return null;
return {
id: 'test',
name: 'Test User',
email: 'test@example.com',
};
},
}),
process.env.AUTH_AUTHENTIK_ID && Authentik,
].filter(Boolean) as Provider[];
export const providerMap = providers
.map((provider) => {
if (typeof provider === 'function') {
const providerData = provider();
return { id: providerData.id, name: providerData.name };
} else {
return { id: provider.id, name: provider.name };
}
})
.filter((provider) => provider.id !== 'credentials');
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [process.env.AUTH_AUTHENTIK_ISSUER ? Authentik : null].filter(
(x) => x !== null,
),
providers,
session: {
strategy: 'jwt',
},
pages: {
signIn: '/login',
signOut: '/logout',
},
callbacks: {
authorized: async ({ auth }) => {
return !!auth;
authorized({ auth }) {
return !!auth?.user;
},
},
});

View file

@ -0,0 +1,24 @@
/* eslint-disable @typescript-eslint/no-unused-expressions */
import React from 'react';
import { IconButton } from './icon-button';
import { faOpenid } from '@fortawesome/free-brands-svg-icons';
describe('<IconButton />', () => {
it('renders', () => {
cy.mount(<IconButton icon={faOpenid}>Button</IconButton>);
});
it('is clickable', () => {
const onClick = cy.stub();
cy.mount(
<IconButton icon={faOpenid} onClick={onClick} data-cy='icon-button'>
Button
</IconButton>,
);
cy.getBySel('icon-button')
.click()
.then(() => {
expect(onClick).to.be.calledOnce;
});
});
});

View file

@ -6,23 +6,25 @@ export default function LabeledInput({
label,
placeholder,
value,
...props
}: {
type: 'text' | 'email' | 'password';
label: string;
placeholder?: string;
value?: string;
}) {
} & React.InputHTMLAttributes<HTMLInputElement>) {
const elementId = Math.random().toString(36).substring(2, 15);
return (
<div className='flex flex-col gap-1'>
<Label htmlFor={elementId}>{label}</Label>
<Label htmlFor={name}>{label}</Label>
<Input
type={type}
placeholder={placeholder}
defaultValue={value}
id={elementId}
{...props}
/>
</div>
);

View file

@ -1,23 +1,47 @@
import { signIn } from '@/auth';
import LabeledInput from '@/components/labeled-input';
import { Button } from '@/components/ui/button';
import { AuthError } from 'next-auth';
import { redirect } from 'next/navigation';
const SIGNIN_ERROR_URL = '/error';
export default function LoginForm() {
return (
<form className='flex flex-col gap-5 w-full'>
<form
className='flex flex-col gap-5 w-full'
data-cy='login-form'
action={async (formData) => {
'use server';
try {
await signIn('credentials', formData);
} catch (error) {
if (error instanceof AuthError) {
return redirect(`${SIGNIN_ERROR_URL}?error=${error.type}`);
}
throw error;
}
}}
>
<LabeledInput
type='email'
label='E-Mail'
placeholder='Enter your E-Mail'
name='email'
data-cy='email-input'
/>
<LabeledInput
type='password'
label='Password'
placeholder='Enter your Password'
name='password'
data-cy='password-input'
/>
<Button
className='hover:bg-blue-600 hover:text-white'
type='submit'
variant='secondary'
data-cy='login-button'
>
Login
</Button>

View file

@ -5,10 +5,11 @@ import { faOpenid } from '@fortawesome/free-brands-svg-icons';
export default function SSOLogin({
provider,
providerDisplayName,
...props
}: {
provider: string;
providerDisplayName: string;
}) {
} & React.HTMLProps<HTMLFormElement>) {
return (
<form
className='flex flex-col items-center gap-4 w-full'
@ -16,6 +17,7 @@ export default function SSOLogin({
'use server';
await signIn(provider);
}}
{...props}
>
<IconButton
className='w-full'

View file

@ -1,18 +0,0 @@
import { signOut } from '@/auth';
import { IconButton } from '@/components/icon-button';
import { faDoorOpen } from '@fortawesome/free-solid-svg-icons';
export function Logout() {
return (
<form
action={async () => {
'use server';
await signOut({ redirectTo: '/login' });
}}
>
<IconButton type='submit' variant='destructive' icon={faDoorOpen}>
Sign Out
</IconButton>
</form>
);
}

View file

@ -0,0 +1,41 @@
import React from 'react';
import { ThemePicker } from '@/components/user/theme-picker';
import { ThemeProvider } from '../theme-provider';
describe('<ThemePicker />', () => {
it('renders', () => {
cy.mount(<ThemePicker />);
});
it('toggle open and close', () => {
cy.mount(<ThemePicker />);
cy.getBySel('theme-picker').click();
cy.getBySel('theme-picker-content').should('exist');
cy.get('html').click();
cy.getBySel('theme-picker-content').should('not.exist');
});
it('enable dark mode', () => {
cy.mount(
<ThemeProvider>
<ThemePicker />
</ThemeProvider>,
);
cy.getBySel('theme-picker').click();
cy.getBySel('dark-theme').click();
cy.get('html').should('have.attr', 'data-theme', 'dark');
});
it('enable light mode', () => {
cy.mount(
<ThemeProvider>
<ThemePicker />
</ThemeProvider>,
);
cy.getBySel('theme-picker').click();
cy.getBySel('light-theme').click();
cy.get('html').should('have.attr', 'data-theme', 'light');
});
});

View file

@ -18,20 +18,26 @@ export function ThemePicker() {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant='outline' size='icon'>
<Button variant='outline' size='icon' data-cy='theme-picker'>
<Sun className='h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0' />
<Moon className='absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100' />
<span className='sr-only'>Toggle theme</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align='end'>
<DropdownMenuItem onClick={() => setTheme('light')}>
<DropdownMenuContent align='end' data-cy='theme-picker-content'>
<DropdownMenuItem
onClick={() => setTheme('light')}
data-cy='light-theme'
>
Light
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme('dark')}>
<DropdownMenuItem onClick={() => setTheme('dark')} data-cy='dark-theme'>
Dark
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme('system')}>
<DropdownMenuItem
onClick={() => setTheme('system')}
data-cy='system-theme'
>
System
</DropdownMenuItem>
</DropdownMenuContent>

View file

@ -1,18 +1,4 @@
import { auth } from '@/auth';
export default auth((req) => {
if (
!req.auth &&
req.nextUrl.pathname !== '/login' &&
process.env.MEETUP_SKIP_LOGIN !== 'true'
) {
const newUrl = new URL('/login', req.nextUrl.origin);
return Response.redirect(newUrl);
} else if (req.auth != null && req.nextUrl.pathname === '/') {
const newUrl = new URL('/home', req.nextUrl.origin);
return Response.redirect(newUrl);
}
});
export { auth as middleware } from '@/auth';
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],

View file

@ -20,7 +20,8 @@
],
"paths": {
"@/*": ["./src/*"]
}
},
"types": ["node", "cypress"]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]

1319
yarn.lock

File diff suppressed because it is too large Load diff