Skip to content

Commit

Permalink
Merge pull request #130 from denoland/fix-signup-failure
Browse files Browse the repository at this point in the history
fix: signup error handling
  • Loading branch information
iuioiua authored Apr 28, 2023
2 parents 68985a0 + 9dc7c46 commit ed86daa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions routes/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ export const handler: Handlers<any, State> = {
const { data, error } = await ctx.state.supabaseClient
.auth.signUp({ email, password });

let redirectUrl = new URL(req.url).searchParams.get("redirect_url") ??
REDIRECT_PATH_AFTER_LOGIN;
if (error) {
redirectUrl = `/signup?error=${encodeURIComponent(error.message)}`;
return new Response(null, {
headers: {
location: `/signup?error=${encodeURIComponent(error.message)}`,
},
status: 302,
});
}

const { id } = await stripe.customers.create({ email });
Expand All @@ -33,6 +36,8 @@ export const handler: Handlers<any, State> = {
stripeCustomerId: id,
});

const redirectUrl = new URL(req.url).searchParams.get("redirect_url") ??
REDIRECT_PATH_AFTER_LOGIN;
return new Response(null, {
headers: { location: redirectUrl },
status: 302,
Expand Down

0 comments on commit ed86daa

Please sign in to comment.