Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new auth errors + update oauth icons for remix-auth example #125

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions remix-auth/app/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ export function BackIcon() {
export const OAuthIcons = {
"builtin::oauth_apple": <AppleIcon />,
"builtin::oauth_azure": <AzureIcon />,
"builtin::oauth_discord": <DiscordIcon />,
"builtin::oauth_github": <GithubIcon />,
"builtin::oauth_google": <GoogleIcon />,
"builtin::oauth_slack": <SlackIcon />,
};

function AppleIcon() {
Expand Down Expand Up @@ -153,6 +155,23 @@ function AzureIcon() {
);
}

function DiscordIcon() {
return (
<svg
width="28"
height="28"
viewBox="0 0 32 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M26.308 6.84247C24.4227 5.96933 22.4323 5.3499 20.3879 5C20.1081 5.50591 19.8549 6.02642 19.6295 6.55936C17.4517 6.2274 15.2371 6.2274 13.0593 6.55936C12.8338 6.02648 12.5806 5.50597 12.301 5C10.2552 5.35286 8.26356 5.97376 6.37632 6.84703C2.62968 12.4543 1.61403 17.9224 2.12186 23.3128C4.31598 24.9526 6.77184 26.1998 9.38266 27C9.97054 26.2002 10.4907 25.3517 10.9377 24.4635C10.0887 24.1427 9.26929 23.747 8.48889 23.2808C8.69428 23.1301 8.89515 22.9749 9.08925 22.8242C11.36 23.9044 13.8385 24.4645 16.3478 24.4645C18.8571 24.4645 21.3356 23.9044 23.6064 22.8242C23.8027 22.9863 24.0036 23.1416 24.2067 23.2808C23.4248 23.7477 22.6039 24.1442 21.7533 24.4658C22.1998 25.3535 22.72 26.2013 23.3084 27C25.9215 26.203 28.3792 24.9564 30.5737 23.3151C31.1696 17.0639 29.5558 11.6461 26.308 6.84247ZM11.581 19.9977C10.1658 19.9977 8.99672 18.6986 8.99672 17.1005C8.99672 15.5023 10.1252 14.1918 11.5765 14.1918C13.0277 14.1918 14.1878 15.5023 14.163 17.1005C14.1382 18.6986 13.0232 19.9977 11.581 19.9977ZM21.1146 19.9977C19.6972 19.9977 18.5326 18.6986 18.5326 17.1005C18.5326 15.5023 19.6611 14.1918 21.1146 14.1918C22.5681 14.1918 23.7192 15.5023 23.6944 17.1005C23.6696 18.6986 22.5568 19.9977 21.1146 19.9977Z"
fill="#5865F2"
/>
</svg>
);
}

function GithubIcon() {
return (
<svg
Expand Down Expand Up @@ -200,3 +219,48 @@ function GoogleIcon() {
</svg>
);
}

function SlackIcon() {
return (
<svg
width="28"
height="28"
viewBox="0 0 32 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M8.46254 19.43C8.46254 20.9332 7.23453 22.1612 5.73127 22.1612C4.22801 22.1612 3 20.9332 3 19.43C3 17.9267 4.22801 16.6987 5.73127 16.6987H8.46254V19.43Z"
fill="#E01E5A"
/>
<path
d="M9.83875 19.43C9.83875 17.9267 11.0668 16.6987 12.57 16.6987C14.0733 16.6987 15.3013 17.9267 15.3013 19.43V26.2687C15.3013 27.772 14.0733 29 12.57 29C11.0668 29 9.83875 27.772 9.83875 26.2687V19.43Z"
fill="#E01E5A"
/>
<path
d="M12.57 8.46254C11.0668 8.46254 9.83875 7.23453 9.83875 5.73127C9.83875 4.22801 11.0668 3 12.57 3C14.0733 3 15.3013 4.22801 15.3013 5.73127V8.46254H12.57Z"
fill="#36C5F0"
/>
<path
d="M12.57 9.83881C14.0733 9.83881 15.3013 11.0668 15.3013 12.5701C15.3013 14.0733 14.0733 15.3013 12.57 15.3013H5.73127C4.22801 15.3013 3 14.0733 3 12.5701C3 11.0668 4.22801 9.83881 5.73127 9.83881H12.57Z"
fill="#36C5F0"
/>
<path
d="M23.5375 12.5701C23.5375 11.0668 24.7655 9.83881 26.2688 9.83881C27.772 9.83881 29 11.0668 29 12.5701C29 14.0733 27.772 15.3013 26.2688 15.3013H23.5375V12.5701Z"
fill="#2EB67D"
/>
<path
d="M22.1612 12.57C22.1612 14.0733 20.9332 15.3013 19.43 15.3013C17.9267 15.3013 16.6987 14.0733 16.6987 12.57V5.73127C16.6987 4.22801 17.9267 3 19.43 3C20.9332 3 22.1612 4.22801 22.1612 5.73127V12.57Z"
fill="#2EB67D"
/>
<path
d="M19.4299 23.5374C20.9332 23.5374 22.1612 24.7654 22.1612 26.2686C22.1612 27.7719 20.9332 28.9999 19.4299 28.9999C17.9267 28.9999 16.6987 27.7719 16.6987 26.2686V23.5374H19.4299Z"
fill="#ECB22E"
/>
<path
d="M19.4299 22.1612C17.9267 22.1612 16.6987 20.9332 16.6987 19.43C16.6987 17.9267 17.9267 16.6987 19.4299 16.6987H26.2687C27.772 16.6987 29 17.9267 29 19.43C29 20.9332 27.772 22.1612 26.2687 22.1612H19.4299Z"
fill="#ECB22E"
/>
</svg>
);
}
9 changes: 8 additions & 1 deletion remix-auth/app/routes/forgot-password.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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")!
Expand Down
8 changes: 7 additions & 1 deletion remix-auth/app/routes/reset-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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("/");
}
Expand Down
8 changes: 7 additions & 1 deletion remix-auth/app/routes/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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("/");
}
Expand Down
15 changes: 9 additions & 6 deletions remix-auth/app/routes/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
});
Expand Down