Skip to content
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
13 changes: 12 additions & 1 deletion template/app/src/auth/LoginPage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { LoginForm } from "wasp/client/auth";
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { LoginForm, useAuth } from "wasp/client/auth";
import { Link as WaspRouterLink, routes } from "wasp/client/router";
import { AuthPageLayout } from "./AuthPageLayout";

export default function Login() {
const { data: user } = useAuth();
const navigate = useNavigate();

useEffect(() => {
if (user) {
navigate("/demo-app");
}
}, [user, navigate]);

return (
<AuthPageLayout>
<LoginForm />
Expand Down
13 changes: 12 additions & 1 deletion template/app/src/auth/SignupPage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { SignupForm } from "wasp/client/auth";
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { SignupForm, useAuth } from "wasp/client/auth";
import { Link as WaspRouterLink, routes } from "wasp/client/router";
import { AuthPageLayout } from "./AuthPageLayout";

export function Signup() {
const { data: user } = useAuth();
const navigate = useNavigate();

useEffect(() => {
if (user) {
navigate("/demo-app");
}
}, [user, navigate]);

return (
<AuthPageLayout>
<SignupForm />
Expand Down
4 changes: 2 additions & 2 deletions template/app/src/payment/stripe/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async function handleInvoicePaid(

function getInvoicePriceId(invoice: Stripe.Invoice): Stripe.Price["id"] {
const invoiceLineItems = invoice.lines.data;
// We only expect one line item.
// We only expect one line item.
// If your workflow expects more, you should change this function to handle them.
if (invoiceLineItems.length !== 1) {
throw new Error("There should be exactly one line item in Stripe invoice");
Expand Down Expand Up @@ -204,7 +204,7 @@ function getSubscriptionPriceId(
subscription: Stripe.Subscription,
): Stripe.Price["id"] {
const subscriptionItems = subscription.items.data;
// We only expect one subscription item.
// We only expect one subscription item.
// If your workflow expects more, you should change this function to handle them.
if (subscriptionItems.length !== 1) {
throw new Error(
Expand Down
38 changes: 38 additions & 0 deletions template/e2e-tests/tests/authRedirectTests.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { expect, test, type Page } from "@playwright/test";
import { createRandomUser, logUserIn, signUserUp, type User } from "./utils";

let page: Page;
let testUser: User;

test.describe.configure({ mode: "serial" });

test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
testUser = createRandomUser();
await signUserUp({ page, user: testUser });
await logUserIn({ page, user: testUser });
});

test.afterAll(async () => {
await page.close();
});

test.describe("auth redirect tests", () => {
test("logged-in user visiting /login should redirect to /demo-app", async () => {
// User is already logged in from beforeAll
await page.goto("/login");

// Should be redirected to /demo-app
await page.waitForURL("**/demo-app", { timeout: 5000 });
expect(page.url()).toContain("/demo-app");
});

test("logged-in user visiting /signup should redirect to /demo-app", async () => {
// User is already logged in from beforeAll
await page.goto("/signup");

// Should be redirected to /demo-app
await page.waitForURL("**/demo-app", { timeout: 5000 });
expect(page.url()).toContain("/demo-app");
});
});