if (url.pathname === '/auth/check-username' && request.method === 'POST') {
const { username } = await request.json();
const normalizedUsername = (username || '').toLowerCase().trim();
if (!normalizedUsername || !/^[a-z0-9_.]{3,16}$/.test(normalizedUsername)) {
return new Response(JSON.stringify({
available: false,
error: 'Username muss 3–16 Zeichen [a-z0-9_\\.] haben'
}), {
status: 400,
headers: { 'Content-Type': 'application/json', ...CORS_HEADERS }
});
}
const { data, error } = await supabase
.from('profiles')
.select('id')
.ilike('username', normalizedUsername)
.maybeSingle();
console.log('🔍 Username Check:', {
input: username,
normalized: normalizedUsername,
found: !!data,
error
});
return new Response(JSON.stringify({
available: !data,
username: normalizedUsername
}), {
status: 200,
headers: { 'Content-Type': 'application/json', ...CORS_HEADERS }
});
}
if (url.pathname === '/auth/check-username' && request.method === 'POST') {
const { username } = await request.json();
const normalizedUsername = (username || '').toLowerCase().trim();
if (!normalizedUsername || !/^[a-z0-9_.]{3,16}$/.test(normalizedUsername)) {
return new Response(JSON.stringify({
available: false,
error: 'Username muss 3–16 Zeichen [a-z0-9_\\.] haben'
}), {
status: 400,
headers: { 'Content-Type': 'application/json', ...CORS_HEADERS }
});
}
const { data, error } = await supabase
.from('profiles')
.select('id')
.ilike('username', normalizedUsername)
.maybeSingle();
console.log('🔍 Username Check:', {
input: username,
normalized: normalizedUsername,
found: !!data,
error
});
return new Response(JSON.stringify({
available: !data,
username: normalizedUsername
}), {
status: 200,
headers: { 'Content-Type': 'application/json', ...CORS_HEADERS }
});
}