Add redirect logic to login and signup pages for logged-in users

Co-authored-by: vincanger <70215737+vincanger@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-14 14:12:16 +00:00
parent 70448e8186
commit c210e45bff
3 changed files with 26 additions and 4 deletions

View File

@@ -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 { Link as WaspRouterLink, routes } from "wasp/client/router";
import { AuthPageLayout } from "./AuthPageLayout"; import { AuthPageLayout } from "./AuthPageLayout";
export default function Login() { export default function Login() {
const { data: user } = useAuth();
const navigate = useNavigate();
useEffect(() => {
if (user) {
navigate("/demo-app");
}
}, [user, navigate]);
return ( return (
<AuthPageLayout> <AuthPageLayout>
<LoginForm /> <LoginForm />

View File

@@ -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 { Link as WaspRouterLink, routes } from "wasp/client/router";
import { AuthPageLayout } from "./AuthPageLayout"; import { AuthPageLayout } from "./AuthPageLayout";
export function Signup() { export function Signup() {
const { data: user } = useAuth();
const navigate = useNavigate();
useEffect(() => {
if (user) {
navigate("/demo-app");
}
}, [user, navigate]);
return ( return (
<AuthPageLayout> <AuthPageLayout>
<SignupForm /> <SignupForm />

View File

@@ -141,7 +141,7 @@ async function handleInvoicePaid(
function getInvoicePriceId(invoice: Stripe.Invoice): Stripe.Price["id"] { function getInvoicePriceId(invoice: Stripe.Invoice): Stripe.Price["id"] {
const invoiceLineItems = invoice.lines.data; 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 your workflow expects more, you should change this function to handle them.
if (invoiceLineItems.length !== 1) { if (invoiceLineItems.length !== 1) {
throw new Error("There should be exactly one line item in Stripe invoice"); throw new Error("There should be exactly one line item in Stripe invoice");
@@ -204,7 +204,7 @@ function getSubscriptionPriceId(
subscription: Stripe.Subscription, subscription: Stripe.Subscription,
): Stripe.Price["id"] { ): Stripe.Price["id"] {
const subscriptionItems = subscription.items.data; 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 your workflow expects more, you should change this function to handle them.
if (subscriptionItems.length !== 1) { if (subscriptionItems.length !== 1) {
throw new Error( throw new Error(