Skip to content

Commit 348429a

Browse files
committed
Fix login
1 parent 88132fb commit 348429a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

apps/builder/app/shared/db/user.server.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,25 @@ const genericCreateAccount = async (
4444
.eq("email", userData.email)
4545
.single();
4646

47-
if (dbUser.error) {
48-
console.error(dbUser.error);
49-
throw new Error("User not found");
50-
}
51-
52-
if (dbUser) {
47+
if (dbUser.error == null) {
5348
const user = User.parse(dbUser.data);
5449
return user;
5550
}
5651

52+
// https://github.com/PostgREST/postgrest/blob/bfbd033c6e9f38cfbc8b1cfe19ee009a9379e3dd/docs/references/errors.rst#L234
53+
if (dbUser.error.code !== "PGRST116") {
54+
console.error(dbUser.error);
55+
throw new Error("User not found");
56+
}
57+
5758
const newUser = await context.postgrest.client
5859
.from("User")
5960
.insert({
6061
id: crypto.randomUUID(),
6162
...userData,
6263
})
63-
.select();
64+
.select()
65+
.single();
6466

6567
if (newUser.error) {
6668
console.error(newUser.error);

0 commit comments

Comments
 (0)