Skip to content

Commit

Permalink
feat: update redirect to feed page for unauthenticated users (#1464)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Roberts <robertsbt@gmail.com>
  • Loading branch information
OgDev-01 and brandonroberts committed Aug 2, 2023
1 parent 6ce5957 commit 6d8505f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions e2e-tests/UnsignedUsersRedirects.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { test, expect } from "@playwright/test";

test("Homepage redirects to /javascript for unsigned users", async ({ page }) => {
test("Homepage redirects to /feed for unsigned users", async ({ page }) => {
await page.goto("/");
await expect(page).toHaveURL(/.*\/javascript.*/, { timeout: 10000 });
await expect(page).toHaveURL(/\/feed/, { timeout: 10000 });
});

test("Insights Hub redirects to /javascript for unsigned users", async ({ page }) => {
test("Insights Hub redirects to /feed for unsigned users", async ({ page }) => {
await page.goto("/hub/insights");
await expect(page).toHaveURL(/.*\/javascript.*/, { timeout: 10000 });
await expect(page).toHaveURL(/\/feed/, { timeout: 10000 });
});
2 changes: 1 addition & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function middleware(req: NextRequest) {

// Auth condition not met, redirect to home page.
const redirectUrl = req.nextUrl.clone();
redirectUrl.pathname = "/javascript/dashboard/filter/recent";
redirectUrl.pathname = "/feed";
redirectUrl.searchParams.set("redirectedFrom", req.nextUrl.pathname);
return NextResponse.redirect(redirectUrl);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/hub/insights/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const InsightsHub: WithPageLayout = () => {
const currentUser = await supabase.auth.getSession();

if (!currentUser?.data?.session || onboarded === false) {
await router.push("/");
await router.push("/feed");
}
} catch (e: unknown) {
router.push("/");
router.push("/feed");
}
}

Expand Down
4 changes: 2 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Home: WithPageLayout = () => {
async function getAccess() {
const currentUser = await supabase.auth.getSession();
if (!currentUser?.data?.session) {
redirect("/javascript");
redirect("/feed");
}

if (onboarded === undefined) {
Expand All @@ -32,7 +32,7 @@ const Home: WithPageLayout = () => {
if (currentUser?.data?.session && onboarded === true) {
redirect("/hub/insights");
} else {
redirect("/javascript");
redirect("/feed");
}
}

Expand Down

0 comments on commit 6d8505f

Please sign in to comment.