Skip to content

Commit

Permalink
Merge branch 'main' into login-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
fedeya authored Jun 28, 2023
2 parents d5251ce + cdf5b93 commit c533a71
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ export const signUp = async (payload: SignUpPayload): Promise<User> => {
method: 'POST',
body: JSON.stringify(payload),
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json; charset=UTF-8'
}
});

if (!res.ok) {
const isJson = res.headers
.get('Content-Type')
?.includes('application/json');

const data = isJson ? await res.json() : await res.text();

throw new Error(data);
}

const user = await res.json();

return user;
Expand Down
13 changes: 12 additions & 1 deletion src/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ export const signUpHandler =
});

if (user) {
res.json({ error: 'User already exist' });
const response = { error: 'User already exist' };

if (isEdge) {
return new Response(JSON.stringify(response), {
headers: {
'Content-Type': 'application/json'
},
status: 400
});
}

res.json(response);
return;
}

Expand Down

0 comments on commit c533a71

Please sign in to comment.