Skip to content

Commit e9bb91a

Browse files
committed
added fallback to non given name
1 parent f53fb0e commit e9bb91a

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

app/api/v1/auth/signup/route.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,26 @@ export async function POST(request: Request) {
2121
});
2222
}
2323

24+
// using localpart of email as fallback
25+
let newName;
26+
if (name === "" || !name && typeof email === "string") {
27+
const localPart = email.split("@")[0];
28+
// a little transformation can't be missing
29+
newName = localPart
30+
.replace(/[._-]+/g, ' ')
31+
.trim()
32+
.split(' ')
33+
.map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()) // capitalize
34+
.join(' ');
35+
} else {
36+
newName = name;
37+
}
38+
2439
const pb = getServerPB();
2540

2641
// 1. Create the user
2742
const user = await pb.collection('users').create({
28-
name,
43+
newName,
2944
email,
3045
password,
3146
passwordConfirm,

0 commit comments

Comments
 (0)