Skip to content

Commit 0dd6807

Browse files
committed
update profile page and UX experience
1 parent 462a990 commit 0dd6807

File tree

5 files changed

+249
-148
lines changed

5 files changed

+249
-148
lines changed

auth-server/src/app/account/profile/ProfileForm.tsx

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useState } from "react";
4+
import { authClient } from "@/lib/auth-client";
45

56
export default function ProfileForm({
67
user,
@@ -30,27 +31,39 @@ export default function ProfileForm({
3031
setLoading(true);
3132

3233
try {
33-
const response = await fetch("/api/account/profile", {
34-
method: "PATCH",
35-
headers: { "Content-Type": "application/json" },
36-
body: JSON.stringify(formData),
34+
// Use Better Auth's official updateUser method
35+
const { data, error } = await authClient.updateUser({
36+
name: formData.name,
37+
givenName: formData.givenName,
38+
familyName: formData.familyName,
39+
softwareBackground: formData.softwareBackground,
40+
hardwareTier: formData.hardwareTier,
41+
locale: formData.locale,
42+
zoneinfo: formData.zoneinfo,
3743
});
3844

39-
if (response.ok) {
40-
if (redirectUrl) {
41-
// Redirect back to client app
42-
window.location.href = redirectUrl;
43-
} else {
44-
// No redirect URL, just reload current page
45-
window.location.reload();
46-
}
45+
if (error) {
46+
alert(`Error: ${error.message || "Failed to update profile"}`);
47+
setLoading(false);
48+
return;
49+
}
50+
51+
// Better Auth automatically refreshes the session!
52+
// No manual refresh needed
53+
54+
if (redirectUrl) {
55+
// Add cache-busting parameter for client app
56+
const redirectWithRefresh = redirectUrl.includes("?")
57+
? `${redirectUrl}&refresh=${Date.now()}`
58+
: `${redirectUrl}?refresh=${Date.now()}`;
59+
60+
window.location.href = redirectWithRefresh;
4761
} else {
48-
const error = await response.json();
49-
alert(`Error: ${error.message}`);
62+
// Reload to reflect changes in UI
63+
window.location.reload();
5064
}
5165
} catch (error) {
5266
alert("Failed to update profile");
53-
} finally {
5467
setLoading(false);
5568
}
5669
};

auth-server/src/app/account/profile/page.tsx

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,49 @@ export default async function ProfilePage({
2020
const redirectUrl = params.redirect || null;
2121

2222
return (
23-
<div className="min-h-screen bg-gradient-to-br from-slate-50 via-white to-indigo-50/30 py-12 px-4">
23+
<div className="min-h-screen bg-gradient-to-br from-slate-50 via-white to-indigo-50/30 py-8 px-4">
2424
<div className="max-w-3xl mx-auto">
25-
{/* Page Header */}
26-
<div className="mb-10">
27-
<h1 className="text-3xl font-bold text-slate-900 tracking-tight mb-2">Profile Settings</h1>
28-
<p className="text-slate-600">Manage your account details and personalize your experience</p>
25+
{/* Refined Header Section */}
26+
<div className="mb-8">
27+
{/* Back Button - Floating Above */}
28+
{redirectUrl && (
29+
<a
30+
href={redirectUrl}
31+
className="inline-flex items-center gap-2 mb-6 group text-slate-600 hover:text-slate-900 transition-colors duration-200"
32+
>
33+
<div className="flex items-center justify-center w-8 h-8 rounded-lg bg-white border border-slate-200 group-hover:border-slate-300 group-hover:shadow-sm transition-all duration-200">
34+
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
35+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 19l-7-7m0 0l7-7m-7 7h18" />
36+
</svg>
37+
</div>
38+
<span className="text-sm font-medium">Back</span>
39+
</a>
40+
)}
41+
42+
{/* Hero Header */}
43+
<div className="relative">
44+
{/* Decorative accent */}
45+
<div className="absolute -left-3 top-0 bottom-0 w-1 bg-gradient-to-b from-indigo-500 to-indigo-600 rounded-full" />
46+
47+
<div className="pl-6">
48+
<h1 className="text-4xl font-bold text-slate-900 tracking-tight mb-3 bg-gradient-to-r from-slate-900 to-slate-700 bg-clip-text">
49+
Profile Settings
50+
</h1>
51+
<p className="text-base text-slate-600 leading-relaxed max-w-xl">
52+
Manage your account details and personalize your learning experience
53+
</p>
54+
</div>
55+
</div>
2956
</div>
3057

31-
{/* Form Card */}
32-
<div className="bg-white rounded-2xl shadow-xl shadow-slate-200/50 border border-slate-200 p-8 md:p-10">
33-
<ProfileForm user={session.user} redirectUrl={redirectUrl} />
58+
{/* Form Card with Enhanced Shadow */}
59+
<div className="relative">
60+
{/* Subtle glow effect */}
61+
<div className="absolute inset-0 bg-gradient-to-r from-indigo-100/20 via-transparent to-purple-100/20 rounded-2xl blur-2xl -z-10" />
62+
63+
<div className="bg-white/80 backdrop-blur-sm rounded-2xl shadow-xl shadow-slate-200/50 border border-slate-200/50 p-8 md:p-10">
64+
<ProfileForm user={session.user} redirectUrl={redirectUrl} />
65+
</div>
3466
</div>
3567
</div>
3668
</div>

auth-server/src/app/api/account/profile/route.ts

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

0 commit comments

Comments
 (0)