From 159c2b23a864b9f8be7eb61a389aff44757e9777 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Fri, 1 Mar 2024 13:57:28 +0000 Subject: [PATCH] Use new auth errors + update oauth icons --- remix-auth/app/icons.tsx | 64 +++++++++++++++++++++++ remix-auth/app/routes/forgot-password.tsx | 9 +++- remix-auth/app/routes/reset-password.tsx | 8 ++- remix-auth/app/routes/signin.tsx | 8 ++- remix-auth/app/routes/signup.tsx | 15 +++--- 5 files changed, 95 insertions(+), 9 deletions(-) diff --git a/remix-auth/app/icons.tsx b/remix-auth/app/icons.tsx index bbb4992..bacb3ef 100644 --- a/remix-auth/app/icons.tsx +++ b/remix-auth/app/icons.tsx @@ -65,8 +65,10 @@ export function BackIcon() { export const OAuthIcons = { "builtin::oauth_apple": , "builtin::oauth_azure": , + "builtin::oauth_discord": , "builtin::oauth_github": , "builtin::oauth_google": , + "builtin::oauth_slack": , }; function AppleIcon() { @@ -153,6 +155,23 @@ function AzureIcon() { ); } +function DiscordIcon() { + return ( + + + + ); +} + function GithubIcon() { return ( ); } + +function SlackIcon() { + return ( + + + + + + + + + + + ); +} diff --git a/remix-auth/app/routes/forgot-password.tsx b/remix-auth/app/routes/forgot-password.tsx index d897ad7..133854a 100644 --- a/remix-auth/app/routes/forgot-password.tsx +++ b/remix-auth/app/routes/forgot-password.tsx @@ -1,5 +1,6 @@ import { useLoaderData, Link, useActionData } from "@remix-run/react"; import auth from "~/services/auth.server"; +import { UserError } from "@edgedb/auth-remix/server"; import { BackIcon } from "../icons"; import { type ActionFunctionArgs, json } from "@remix-run/node"; import ForgotPasswordForm from "~/components/auth/ForgotPasswordForm"; @@ -48,7 +49,13 @@ export async function action({ request }: ActionFunctionArgs) { request, async ({ error }) => { if (error) { - return json({ error: error.message, message: null }); + return json({ + error: + error instanceof UserError + ? `Error sending password reset: ${error.message}` + : `Unknown error occurred sending password reset`, + message: null, + }); } else { const email = (await request.clone().formData()) .get("email")! diff --git a/remix-auth/app/routes/reset-password.tsx b/remix-auth/app/routes/reset-password.tsx index 71f7a4e..0868e70 100644 --- a/remix-auth/app/routes/reset-password.tsx +++ b/remix-auth/app/routes/reset-password.tsx @@ -6,6 +6,7 @@ import { redirect, } from "@remix-run/node"; import auth from "~/services/auth.server"; +import { UserError } from "@edgedb/auth-remix/server"; import { BackIcon } from "../icons"; import ResetPasswordForm from "~/components/auth/ResetPasswordForm"; @@ -71,7 +72,12 @@ export default function ResetPasswordPage() { export const action = async ({ request }: ActionFunctionArgs) => { return auth.emailPasswordResetPassword(request, ({ error }) => { if (error) { - return json({ error: error.message }); + return json({ + error: + error instanceof UserError + ? `Error resetting password: ${error.message}` + : `Unknown error occurred resetting password`, + }); } else { return redirect("/"); } diff --git a/remix-auth/app/routes/signin.tsx b/remix-auth/app/routes/signin.tsx index 6d49df7..ac1e4b8 100644 --- a/remix-auth/app/routes/signin.tsx +++ b/remix-auth/app/routes/signin.tsx @@ -6,6 +6,7 @@ import { } from "@remix-run/react"; import { type ActionFunctionArgs, json, redirect } from "@remix-run/node"; import auth from "~/services/auth.server"; +import { UserError } from "@edgedb/auth-remix/server"; import clientAuth from "~/services/auth"; import { BackIcon, OAuthIcons } from "../icons"; import SigninForm from "../components/auth/SigninForm"; @@ -86,7 +87,12 @@ export default function SignInPage() { export const action = ({ request }: ActionFunctionArgs) => { return auth.emailPasswordSignIn(request, ({ error }) => { if (error) { - return json({ error: error.message }); + return json({ + error: + error instanceof UserError + ? `Error signing in: ${error.message}` + : `Unknown error occurred signing in`, + }); } else { return redirect("/"); } diff --git a/remix-auth/app/routes/signup.tsx b/remix-auth/app/routes/signup.tsx index 768d5e8..231f629 100644 --- a/remix-auth/app/routes/signup.tsx +++ b/remix-auth/app/routes/signup.tsx @@ -6,6 +6,7 @@ import { } from "@remix-run/react"; import { json, redirect } from "@remix-run/node"; import auth from "~/services/auth.server"; +import { UserError } from "@edgedb/auth-remix/server"; import { BackIcon } from "../icons"; import SignupForm from "../components/auth/SignupForm"; import { type ActionFunctionArgs } from "@remix-run/node"; @@ -90,7 +91,13 @@ export const action = async ({ request }: ActionFunctionArgs) => { else return auth.emailPasswordSignUp(request, async ({ error, tokenData }) => { if (error) { - return json({ error: error.message, message: null }); + return json({ + error: + error instanceof UserError + ? `Error signing up: ${error.message}` + : `Unknown error occurred signing up`, + message: null, + }); } else { try { if (!tokenData) { @@ -106,13 +113,9 @@ export const action = async ({ request }: ActionFunctionArgs) => { return redirect("/"); } catch (e) { - let err: any = e instanceof Error ? e.message : String(e); - try { - err = JSON.parse(err); - } catch {} return json({ error: `Error signing up: ${ - err?.error?.message ?? JSON.stringify(err) + e instanceof Error ? e.message : String(e) }`, message: null, });