Skip to content

Commit

Permalink
feature: prevent auth users from accessing login/signup page (#85)
Browse files Browse the repository at this point in the history
Co-authored-by: Ebenezer Arthur <[email protected]>
  • Loading branch information
ebarthur and Ebenezer Arthur authored Sep 23, 2024
1 parent 3abd82b commit 3091d79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 10 additions & 1 deletion client/app/routes/create-account.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Prisma, type User } from "@prisma/client";
import {
json,
LoaderFunctionArgs,
redirect,
type ActionFunctionArgs,
type MetaFunction,
Expand All @@ -22,8 +23,16 @@ import { sendEmailVerification } from "~/lib/send-email-verification";
import { USERNAME_REGEX } from "~/lib/username-regex";
import { values } from "~/lib/values.server";
import { restrictedUsernames } from "~/lib/restrict-usernames";
import { checkAuth } from "~/lib/check-auth";

export const loader = async ({ request }: LoaderFunctionArgs) => {
try {
await checkAuth(request);
return redirect("/discussions");
} catch (error) {
//
}

export const loader = async () => {
const school = values.get("shortName");
const emailExtensions = values.get("emailExtensions") as string[];

Expand Down
16 changes: 13 additions & 3 deletions client/app/routes/login.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
json,
LoaderFunctionArgs,
redirect,
type ActionFunctionArgs,
type MetaFunction,
} from "@remix-run/node";
Expand All @@ -12,13 +14,21 @@ import {
import { useForm, type FieldValues } from "react-hook-form";
import { Button } from "~/components/button";
import { Input } from "~/components/input";
import { checkAuth } from "~/lib/check-auth";
import { authCookie } from "~/lib/cookies.server";
import { signUser } from "~/lib/jwt.server";
import { compare } from "~/lib/password.server";
import { prisma } from "~/lib/prisma.server";
import { values } from "~/lib/values.server";

export const loader = async () => {
export const loader = async ({ request }: LoaderFunctionArgs) => {
try {
await checkAuth(request);
return redirect("/discussions");
} catch (error) {
//
}

const school = values.get("shortName");

return { school };
Expand Down Expand Up @@ -118,8 +128,8 @@ export default function Login() {
<h1 className="font-bold text-2xl mb-2">Login</h1>

<div className="rounded-lg p-2 bg-blue-50 text-blue-500 my-2 dark:bg-blue-700 dark:bg-opacity-10 dark:text-blue-400">
<i className="i-lucide-hand inline-block" /> If this is your first time here, you might need to create an
account.
<i className="i-lucide-hand inline-block" /> If this is your first
time here, you might need to create an account.
</div>

{actionData && (
Expand Down

0 comments on commit 3091d79

Please sign in to comment.