From 1836729e9fa1e94a775e00a6871b920c51ec704d Mon Sep 17 00:00:00 2001 From: Korbs Date: Tue, 16 Jul 2024 05:18:32 -0400 Subject: [PATCH] Theme both the sign-in and sign-up pages --- src/layouts/SignInUp.astro | 155 +++++++++++++++++++++++++++++++++++++ src/pages/signin.astro | 95 +++-------------------- src/pages/signup.astro | 103 +++++++----------------- 3 files changed, 193 insertions(+), 160 deletions(-) create mode 100644 src/layouts/SignInUp.astro diff --git a/src/layouts/SignInUp.astro b/src/layouts/SignInUp.astro new file mode 100644 index 0000000..0e481ee --- /dev/null +++ b/src/layouts/SignInUp.astro @@ -0,0 +1,155 @@ +--- +// Properties +const {Title, Type} = Astro.props + +// Check if user is already logged in, redirect if so +const { user } = Astro.locals; +if (user) { + return Astro.redirect("/account"); +} +--- + + +
+
+ +
+
+

{Title}

+
+ { + ()=> { + if (Type === "SignUp") { + return + } else { + return null + } + } + } + + +
+ { + ()=> { + if (Type === "SignIn") { + return

Don't have an account? Sign Up

+ + } else if (Type === "SignUp") { + return

Already have an account? Sign In

+ + } + } + } +
+ +
+ +
+
+ + \ No newline at end of file diff --git a/src/pages/signin.astro b/src/pages/signin.astro index d00c3ac..f17c38a 100644 --- a/src/pages/signin.astro +++ b/src/pages/signin.astro @@ -1,11 +1,8 @@ --- -import Layout from "../layouts/Layout.astro"; -import { SESSION_COOKIE, createAdminClient } from "../server/appwrite"; +import SignInUp from "../layouts/SignInUp.astro"; -const { user } = Astro.locals; -if (user) { - return Astro.redirect("/account"); -} +import { ID } from "node-appwrite"; +import { SESSION_COOKIE, createAdminClient } from "../server/appwrite"; if (Astro.request.method === "POST") { const data = await Astro.request.formData(); @@ -17,89 +14,15 @@ if (Astro.request.method === "POST") { const session = await account.createEmailPasswordSession(email, password); Astro.cookies.set(SESSION_COOKIE, session.secret, { - path: "/", - expires: new Date(session.expire), - sameSite: "strict", - secure: true, - httpOnly: true, + path: "/", + expires: new Date(session.expire), + sameSite: "strict", + secure: true, + httpOnly: true, }); return Astro.redirect("/account"); } --- - -
-

Demo sign in

-
-
-
    -
  • -

    - This is a demo project for Appwrite server side rendering. View the source code on the - GitHub repository. -

    -
  • -
  • - -
    - -
    -
  • -
  • - -
    - - -
    -
  • -
  • - -
  • - or -
  • -
-
-
- -
-
- -
-
+ \ No newline at end of file diff --git a/src/pages/signup.astro b/src/pages/signup.astro index 4d2fe7c..344e663 100644 --- a/src/pages/signup.astro +++ b/src/pages/signup.astro @@ -1,88 +1,43 @@ --- +import SignInUp from "../layouts/SignInUp.astro"; + import { ID } from "node-appwrite"; import { SESSION_COOKIE, createAdminClient } from "../server/appwrite"; -const { user } = Astro.locals; -if (user) { - return Astro.redirect("/account"); -} + if (Astro.request.method === "POST") { - const data = await Astro.request.formData(); + const data = await Astro.request.formData(); - const email = data.get("email") as string; - const password = data.get("password") as string; - const name = data.get("name") as string; + const email = data.get("email") as string; + const password = data.get("password") as string; + const name = data.get("name") as string; - const { account } = createAdminClient(); + const { account } = createAdminClient(); - await account.create(ID.unique(), email, password, name); - const session = await account.createEmailPasswordSession(email, password); - const promise = account.createVerification("http://localhost:4321/verify"); + await account.create(ID.unique(), email, password, name); + const session = await account.createEmailPasswordSession(email, password); + const promise = account.createVerification("http://localhost:4321/verify"); - promise.then( - function (response) { - console.log('VERI:' + response); - }, - function (error) { - console.log(error); - }, - ); + promise.then( + function (response) { + console.log('VERI:' + response); + }, + function (error) { + console.log(error); + }, + ); - Astro.cookies.set(SESSION_COOKIE, session.secret, { - path: "/", - expires: new Date(session.expire), - sameSite: "strict", - secure: true, - httpOnly: true, - }); + Astro.cookies.set(SESSION_COOKIE, session.secret, { + path: "/", + expires: new Date(session.expire), + sameSite: "strict", + secure: true, + httpOnly: true, + }); - return Astro.redirect("/account"); -} + return Astro.redirect("/account"); + } --- -
- - - - - - - - - - - -
- - - - -
- - -
- -Create Anonymous Session \ No newline at end of file + \ No newline at end of file