mirror of
https://github.com/wasp-lang/open-saas.git
synced 2025-11-19 23:36:40 +01:00
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:
@@ -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 />
|
||||||
|
|||||||
@@ -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 />
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user