fix: Use username field instead of display_name in profile
- Updated profile-actions.ts to use username column - Updated ProfileForm.tsx to use username - Updated settings page to pass username - Matches database schema (profiles.username)
This commit is contained in:
@@ -44,7 +44,7 @@ export default async function SettingsPage() {
|
|||||||
<ProfileForm
|
<ProfileForm
|
||||||
initialData={{
|
initialData={{
|
||||||
email: profile?.email,
|
email: profile?.email,
|
||||||
display_name: profile?.display_name,
|
username: profile?.username,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import { updateProfile } from '@/services/profile-actions';
|
|||||||
interface ProfileFormProps {
|
interface ProfileFormProps {
|
||||||
initialData: {
|
initialData: {
|
||||||
email?: string;
|
email?: string;
|
||||||
display_name?: string | null;
|
username?: string | null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ProfileForm({ initialData }: ProfileFormProps) {
|
export default function ProfileForm({ initialData }: ProfileFormProps) {
|
||||||
const [displayName, setDisplayName] = useState(initialData.display_name || '');
|
const [username, setUsername] = useState(initialData.username || '');
|
||||||
const [isPending, startTransition] = useTransition();
|
const [isPending, startTransition] = useTransition();
|
||||||
const [status, setStatus] = useState<'idle' | 'success' | 'error'>('idle');
|
const [status, setStatus] = useState<'idle' | 'success' | 'error'>('idle');
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
@@ -24,7 +24,7 @@ export default function ProfileForm({ initialData }: ProfileFormProps) {
|
|||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.set('display_name', displayName);
|
formData.set('username', username);
|
||||||
|
|
||||||
startTransition(async () => {
|
startTransition(async () => {
|
||||||
const result = await updateProfile(formData);
|
const result = await updateProfile(formData);
|
||||||
@@ -66,16 +66,16 @@ export default function ProfileForm({ initialData }: ProfileFormProps) {
|
|||||||
<p className="mt-1 text-xs text-zinc-500">E-Mail kann nicht geändert werden</p>
|
<p className="mt-1 text-xs text-zinc-500">E-Mail kann nicht geändert werden</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Display Name */}
|
{/* Username */}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-zinc-400 mb-2">
|
<label className="block text-sm font-medium text-zinc-400 mb-2">
|
||||||
Anzeigename
|
Benutzername
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={displayName}
|
value={username}
|
||||||
onChange={(e) => setDisplayName(e.target.value)}
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
placeholder="Dein Name"
|
placeholder="Dein Benutzername"
|
||||||
className="w-full px-4 py-3 bg-zinc-800 border border-zinc-700 rounded-xl text-white placeholder-zinc-500 focus:outline-none focus:ring-2 focus:ring-orange-500 focus:border-transparent"
|
className="w-full px-4 py-3 bg-zinc-800 border border-zinc-700 rounded-xl text-white placeholder-zinc-500 focus:outline-none focus:ring-2 focus:ring-orange-500 focus:border-transparent"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ export async function updateProfile(formData: FormData): Promise<ProfileUpdateRe
|
|||||||
return { success: false, error: 'Nicht autorisiert' };
|
return { success: false, error: 'Nicht autorisiert' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const displayName = formData.get('display_name') as string;
|
const username = formData.get('username') as string;
|
||||||
|
|
||||||
const { error } = await supabase
|
const { error } = await supabase
|
||||||
.from('profiles')
|
.from('profiles')
|
||||||
.upsert({
|
.upsert({
|
||||||
id: user.id,
|
id: user.id,
|
||||||
display_name: displayName?.trim() || null,
|
username: username?.trim() || null,
|
||||||
updated_at: new Date().toISOString(),
|
updated_at: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -98,14 +98,14 @@ export async function getProfile() {
|
|||||||
|
|
||||||
const { data: profile } = await supabase
|
const { data: profile } = await supabase
|
||||||
.from('profiles')
|
.from('profiles')
|
||||||
.select('id, display_name, avatar_url, created_at, updated_at')
|
.select('id, username, avatar_url, updated_at')
|
||||||
.eq('id', user.id)
|
.eq('id', user.id)
|
||||||
.single();
|
.single();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
display_name: profile?.display_name || null,
|
username: profile?.username || null,
|
||||||
avatar_url: profile?.avatar_url || null,
|
avatar_url: profile?.avatar_url || null,
|
||||||
created_at: user.created_at,
|
created_at: user.created_at,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user