diff --git a/src/components/Head.astro b/src/components/Head.astro new file mode 100644 index 0000000..f703729 --- /dev/null +++ b/src/components/Head.astro @@ -0,0 +1,9 @@ +--- +const { Title } = Astro.props +--- + + + + + {Title} + \ No newline at end of file diff --git a/src/components/Header.astro b/src/components/Header.astro new file mode 100644 index 0000000..24c6a78 --- /dev/null +++ b/src/components/Header.astro @@ -0,0 +1,35 @@ +--- +if (Astro.cookies.get('sb-access-token') && Astro.cookies.get('sb-refresh-token')) { + var IsLoggedIn = true +} else { + var IsLoggedIn = false +} + +// Supabase Data +import { supabase } from "../library/supabase" +const { data: { user } } = await supabase.auth.getUser() +const avatar = user?.user_metadata.avatar_url +const beta = user?.user_metadata.beta +--- + +
+
+

Supabase Demo {beta ? Beta : null}

+
+
+ {IsLoggedIn + ? + + Account + Sign Out + : + Register + Sign in + } +
+
+ + + \ No newline at end of file diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro new file mode 100644 index 0000000..fd18145 --- /dev/null +++ b/src/layouts/Base.astro @@ -0,0 +1,16 @@ +--- +const {Title} = Astro.props +import Head from "@components/Head.astro" +import Header from "@components/Header.astro" +import '@styles/root.scss' +--- + + + +
+ +
+ +
+ + \ No newline at end of file diff --git a/src/pages/account.astro b/src/pages/account.astro index 165f316..a32d9c3 100644 --- a/src/pages/account.astro +++ b/src/pages/account.astro @@ -1,45 +1,146 @@ --- -const { user, users } = Astro.locals -if (!user) {return Astro.redirect("/signin")} -import { SESSION_COOKIE, createAdminClient } from "../server/appwrite"; +import Base from "@layouts/Base.astro" -if (user.emailVerification) {var EmailIsVerified = true} -else {var EmailIsVerified = false} +// Messages +if (Astro.url.href.endsWith('CheckEmail')) {var MessageCheckEmail = true} +else {var MessageCheckEmail = false} -if (Astro.cookies.get('anonymous')) {var AN = true} -else {var AN = false} +if (Astro.url.href.endsWith('AvatarUpdated')) {var MessageAvatarUpdated = true} +else {var MessageAvatarUpdated = false} -const { account } = createAdminClient(); -// const session = await account.createMagicURLToken(user.$id,user.email); +if (Astro.url.href.endsWith('NameUpdated')) {var MessageNameUpdated = true} +else {var MessageNameUpdated = false} + +if (Astro.url.href.endsWith('EmailConfirmed')) {var MessageEmailConfirmed = true} +else {var MessageEmailConfirmed = false} + +if (Astro.url.href.endsWith('PasswordReset')) {var MessagePasswordReset = true} +else {var MessagePasswordReset = false} + +// Supabase Data +import { supabase } from "../library/supabase" +const { data: { user } } = await supabase.auth.getUser() +const avatarUrl = user?.user_metadata.avatar_url +const displayName = user?.user_metadata.full_name +const email = user?.email +const id = user?.id + +// Get User Preferences +const user_plan = user?.user_metadata.plan +const user_theme = user?.user_metadata.theme +const user_color_scheme = user?.user_metadata.color_scheme +const user_beta = user?.user_metadata.beta + +// Date - Readable Format (MONTH DAY, YEAR at #:##:## AM/PM / December 9, 2023 at 5:12:43 PM) +const dateFormat = { year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' } + +/// Created Date +const createdDate = new Date(user?.created_at) +const createDate = createdDate.toLocaleDateString('en-US', dateFormat) + +/// Last Logged In +const lastSignIn = new Date(user?.last_sign_in_at) +const lastSignInDate = lastSignIn.toLocaleDateString('en-US', dateFormat) --- -

Email: {AN ? None : {user.email}}

-

ID: {user.$id}

- -

Name: {AN ? Anonymous : {user.name}}

-

Created at: {user.$createdAt}

-

Last login: {user.accessedAt}

-

Last updated: {user.$updatedAt}

-

Labels: - {user.labels.map((data) => -

- )} -

+ + +
+ + + + +
+
+
+ +
-Theme: {user.prefs.darkTheme} + +
+ + {MessageCheckEmail ?

Check your email

: null} + {MessageAvatarUpdated ?

Your avatar has been updated

: null} + {MessageNameUpdated ?

Your display name has been updated

: null} + {MessageEmailConfirmed ?

Email confirmed

: null} + {MessagePasswordReset ?

Your new password has been updated

: null} + +

Your Account

+

Plan: {user_plan}

+

Display Name: {displayName}

+

Email: {email}

+
+

ID: {id}

+

Created at: {createDate}

+

Lasted login: {lastSignInDate}

+
+ +

Preferences

+

Theme: {user_theme}

+

Color Scheme: {user_color_scheme}

+ {user_beta ? +
+ : +
+ } +

+
+ +
+

Change Avatar

+
+ + +
+ +
+
+

Update Display Name

+
+ + +
+ +
+
+

Change Email

+
+ + +
+ +
+
+

Change Password

+
+ + +
+
+ + +
+ +
+

Do you want to delete your accout?

+
+ -{EmailIsVerified ? -

Your account is verified

- : -

Your account is not verified

+ -{AN ? -

This is an anonmyous account.

- : -

Not an anonmyous account.

+ \ No newline at end of file diff --git a/src/pages/creator/C6nSFpj9HTCZ5t-N3Rm3-HA.astro b/src/pages/creator/C6nSFpj9HTCZ5t-N3Rm3-HA.astro new file mode 100644 index 0000000..4ab26d2 --- /dev/null +++ b/src/pages/creator/C6nSFpj9HTCZ5t-N3Rm3-HA.astro @@ -0,0 +1,26 @@ +--- +import Base from "@layouts/Base.astro" +const CreatorId = Astro.url.href.split("creator/").pop() +import { supabase } from "@library/supabase" +const { data: { user } } = await supabase.auth.getUser() +const id = user?.id + +let { data: subs } = await supabase + .from('subs') + .select("*") + .eq('UserSubscribed', id) + .eq('Id', CreatorId) +--- + + +
+

Vsause

+
+ {subs[0].Subscribed ? + Unsubscribe + : + Subscribe + } +
+
+ \ No newline at end of file diff --git a/src/pages/index.astro b/src/pages/index.astro index e068fca..96658e3 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,8 +1,55 @@ --- -const { user } = Astro.locals; -if (user) { - return Astro.redirect("/account"); +import Base from "@layouts/Base.astro" + +// Check Cookies +if (Astro.cookies.get('sb-access-token') && Astro.cookies.get('sb-refresh-token')) { + var IsLoggedIn = true +} else { + var IsLoggedIn = false } -return Astro.redirect("/signin"); +// Supabase Data +import { supabase } from "../library/supabase" +const { data: { user } } = await supabase.auth.getUser() +const avatar = user?.user_metadata.avatar_url +const displayName = user?.user_metadata.full_name +const id = user?.id + +// Get Channels +const { data: channels, error } = await supabase + .from('channels') + .select('*') + + + + let { data: subs } = await supabase + .from('subs') + .select("*") + .eq('UserSubscribed', id) + + +console.log(subs) --- + + + {IsLoggedIn + ? +
+ +

Welcome back, {displayName}

+
+ : +
+

Welcome!

+
+ } +
+

Channels

+ {channels.map((channel) => + {channel.creator} + )} +
+ {subs.map((data) => +

{data.Id} | Unsubscribe

+ )} + \ No newline at end of file diff --git a/src/pages/register.astro b/src/pages/register.astro new file mode 100644 index 0000000..0d7596b --- /dev/null +++ b/src/pages/register.astro @@ -0,0 +1,39 @@ +--- +import Base from "@layouts/Base.astro" +--- + + +

Register for Supabase Demo

+

Already have an account? Sign In.

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+

+ Or with +

+
+
+ + + + +
+
+ diff --git a/src/pages/reset-password.astro b/src/pages/reset-password.astro new file mode 100644 index 0000000..e4ee3f2 --- /dev/null +++ b/src/pages/reset-password.astro @@ -0,0 +1,32 @@ +--- +import Base from "@layouts/Base.astro" +--- + + +
+
+

Change Password

+
+ + +
+
+ + +
+ +
+
+ + + \ No newline at end of file diff --git a/src/pages/signin.astro b/src/pages/signin.astro index f17c38a..8bd682e 100644 --- a/src/pages/signin.astro +++ b/src/pages/signin.astro @@ -1,28 +1,31 @@ --- -import SignInUp from "../layouts/SignInUp.astro"; - -import { ID } from "node-appwrite"; -import { SESSION_COOKIE, createAdminClient } from "../server/appwrite"; - -if (Astro.request.method === "POST") { - const data = await Astro.request.formData(); - - const email = data.get("email") as string; - const password = data.get("password") as string; - - const { account } = createAdminClient(); - 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, - }); - - return Astro.redirect("/account"); -} +import Base from "@layouts/Base.astro" --- - \ No newline at end of file + +

Sign In

+

Don't have an account? Sign Up.

+
+
+ + +
+
+ + +
+ +
+

+ Or with +

+ +
+ + + + +
+
+ +