refactor(v5): extract csrfToken into shared lib/csrf.js module

This commit is contained in:
Andras Bacsai committed 2026-06-16 19:42:26 +02:00
1 parent c178dfdb39
commit 6b8f50a90e
3 files changed
+8 -4

No files matched your search

+1 -4
View File
@@ -1,10 +1,7 @@
import { useMemo, useState } from 'react';
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
function csrfToken() {
return document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') ?? '';
}
import { csrfToken } from '@/lib/csrf';
function persistSelection(projectUuid, environmentUuid) {
void fetch('/v5/selection', {
+3
View File
@@ -0,0 +1,3 @@
export function csrfToken() {
return document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') ?? '';
}
+4
View File
@@ -327,6 +327,8 @@ it('defines the v5 home page as a shadcn styled canvas shell', function () {
expect($homePage)
->toContain('Magic')
->toContain("import { AppNavbar } from '@/components/app-navbar';")
->not->toContain("import { csrfToken } from '@/lib/csrf';")
->not->toContain('function csrfToken()')
->toContain('<AppNavbar')
->toContain('bg-background text-foreground')
->toContain('h-dvh overflow-hidden bg-background text-foreground')
@@ -340,6 +342,8 @@ it('defines the v5 home page as a shadcn styled canvas shell', function () {
->not->toContain("'X-CSRF-TOKEN': csrfToken()");
expect($navbar)
->toContain("import { csrfToken } from '@/lib/csrf';")
->not->toContain('function csrfToken()')
->toContain('export function AppNavbar')
->toContain('/coolify-logo.svg')
->toContain('className="fixed inset-x-0 top-0 z-40 border-b border-border bg-background"')