From 2b488abf78c967328ecf84d54600e23648c4913d Mon Sep 17 00:00:00 2001
From: Anna Shaforostova <110382186+gigsanna@users.noreply.github.com>
Date: Mon, 22 Apr 2024 12:13:18 +0200
Subject: [PATCH] Add fake login form (#3)
remove GIGS_MANAGABLE_USER_EMAIL in favour of email login form;
add fake login form storing email in a cookie;
add auth protection: only allow going to /checkout and /backoffice if logged in
---
.env.example | 1 -
README.md | 5 +-
app/(manage)/backoffice/layout.tsx | 13 +
app/(purchase)/checkout/layout.tsx | 13 +
app/(purchase)/checkout/page.tsx | 10 +-
app/setup-error/page.tsx | 11 +-
components/LoginForm.tsx | 28 ++
components/SideNav.tsx | 6 +-
components/SideNavLogoutButton.tsx | 16 ++
components/UserButton.tsx | 43 +++
components/ui/dropdown.tsx | 57 ++++
components/ui/input.tsx | 26 ++
lib/actions.ts | 13 +-
lib/api.ts | 4 +-
lib/applicationMocks.ts | 11 +-
lib/utils.ts | 3 +-
package-lock.json | 438 +++++++++++++++++++++++++++++
package.json | 1 +
18 files changed, 673 insertions(+), 26 deletions(-)
create mode 100644 app/(manage)/backoffice/layout.tsx
create mode 100644 app/(purchase)/checkout/layout.tsx
create mode 100644 components/LoginForm.tsx
create mode 100644 components/SideNavLogoutButton.tsx
create mode 100644 components/UserButton.tsx
create mode 100644 components/ui/dropdown.tsx
create mode 100644 components/ui/input.tsx
diff --git a/.env.example b/.env.example
index 61190b4..285595d 100644
--- a/.env.example
+++ b/.env.example
@@ -1,3 +1,2 @@
GIGS_PROJECT=
GIGS_API_KEY=
-GIGS_MANAGABLE_USER_EMAIL=
diff --git a/README.md b/README.md
index 0148d7d..8360460 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Connect Sessions Buy & Manage example
-This application showcase how Connect Sessions can be used to buy and manag phone plans through Connect from your existing application. This is a developer reference.
+This application showcase how Connect Sessions can be used to buy and manage phone plans through Connect from your existing application. This is a developer reference.
To get the most out of this, please read the [associated guide](https://developers.gigs.com/docs/api/805ba2c145553-example-purchasing-and-managing-subscriptions-using-connect-sessions).
@@ -20,7 +20,7 @@ In order to run this example locally, you need:
- an existing Project with Connect enabled and at least one plan and one add-on configured
- a valid API key
-To setup the example:
+To set up the example:
**Clone the repository**
@@ -45,7 +45,6 @@ Set the required environment variables:
- `GIGS_PROJECT`: The name of your project (the yourproject part from your yourproject.gigs.com Connect url)
- `GIGS_API_KEY`: Your API key
-- `GIGS_MANAGABLE_USER_EMAIL`: The desired email of your user (it does not have to exist in your project yet, but you **should have access to the emails**)
**Start the app**
diff --git a/app/(manage)/backoffice/layout.tsx b/app/(manage)/backoffice/layout.tsx
new file mode 100644
index 0000000..dfdcc61
--- /dev/null
+++ b/app/(manage)/backoffice/layout.tsx
@@ -0,0 +1,13 @@
+import { auth } from '@/lib/applicationMocks'
+import { LoginForm } from '@/components/LoginForm'
+
+type Props = {
+ children: React.ReactNode
+}
+
+const Layout = async ({ children }: Props) => {
+ const currentUser = auth.getUser()
+ return currentUser.email ? <>{children}> :