Skip to content

Commit

Permalink
feat: added signin/signup components, fixed env vars, added supabase/…
Browse files Browse the repository at this point in the history
…init.ts, moved supabase/ into src/supabase/
  • Loading branch information
ErikBjare committed Nov 14, 2023
1 parent 9baa706 commit 838e92f
Show file tree
Hide file tree
Showing 16 changed files with 620 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_SUPABASE_URL=https://qgaehogepxdhqyrilxlt.supabase.co
VITE_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InFnYWVob2dlcHhkaHF5cmlseGx0Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTY1MDYyNTMsImV4cCI6MjAxMjA4MjI1M30.Hzmm7RtxkctfV2BAYAjDnwGtg9VSZS_CN5qbmmeblzI
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.env
.env.local

# Logs
logs
Expand Down
485 changes: 479 additions & 6 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"format": "prettier --write src/ e2e/ supabase/"
},
"dependencies": {
"@supabase/supabase-js": "^2.38.4",
"pinia": "^2.1.7",
"supabase": "^1.112.0",
"vue": "^3.3.4",
Expand Down
3 changes: 3 additions & 0 deletions src/components/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ import { RouterLink } from "vue-router";
<div class="rounded border px-2 py-1">
<RouterLink to="/settings">Settings</RouterLink>
</div>
<div class="rounded border px-2 py-1">
<RouterLink to="/account">Account</RouterLink>
</div>
</nav>
</template>
37 changes: 37 additions & 0 deletions src/components/SignIn.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script setup lang="ts">
import { ref } from "vue";
import { supabase } from "@/supabase/init.ts"; // Import your Supabase instance

Check failure on line 3 in src/components/SignIn.vue

View workflow job for this annotation

GitHub Actions / test (E2E)

An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
const email = ref("");
const password = ref("");
const signIn = async () => {
const { user, error } = await supabase.auth.signIn({

Check failure on line 9 in src/components/SignIn.vue

View workflow job for this annotation

GitHub Actions / test (E2E)

Property 'signIn' does not exist on type 'SupabaseAuthClient'.
email: email.value,
password: password.value,
});
if (error) console.error("Error signing in:", error);
else console.log("User signed in:", user);
};
</script>

<template>
<div class="container mx-auto max-w-md">
<div class="flex flex-col items-center justify-between">
<h1 class="text-2xl font-bold">Sign In</h1>
<input
v-model="email"
type="email"
placeholder="Email"
class="rounded border m-2 p-2"
/>
<input
v-model="password"
type="password"
placeholder="Password"
class="rounded border m-2 p-2"
/>
<button @click="signIn" class="rounded border px-2 py-1">Sign In</button>
</div>
</div>
</template>
41 changes: 41 additions & 0 deletions src/components/SignUp.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script setup lang="ts">
import { ref } from "vue";
import { supabase } from "@/supabase/init"; // Import your Supabase instance
const email = ref("");
const password = ref("");
const signUp = async () => {
const { user, error } = await supabase.auth.signUp({

Check failure on line 9 in src/components/SignUp.vue

View workflow job for this annotation

GitHub Actions / test (E2E)

Property 'user' does not exist on type 'AuthResponse'.

Check failure on line 9 in src/components/SignUp.vue

View workflow job for this annotation

GitHub Actions / test (E2E)

Property 'user' does not exist on type '{ data: { user: User | null; session: Session | null; }; error: null; }'.
email: email.value,
password: password.value,
});
if (error) console.error("Error signing up:", error);
else console.log("User signed up:", user);
};
</script>

<template>
<div class="container max-w-md">
<div class="flex flex-col items-center justify-between">
<h1 class="text-2xl font-bold">Sign Up</h1>
<input
v-model="email"
type="email"
placeholder="Email"
class="rounded border m-2 p-2"
/>
<input
v-model="password"
type="password"
placeholder="Password"
class="rounded border m-2 p-2"
/>
<button @click="signUp" class="border rounded px-2 py-1">Sign Up</button>
<hr />
<router-link to="/forgot-password" class="opacity-30"
>Forgot Password</router-link
>
</div>
</div>
</template>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions src/supabase/functions/stripeWebhook/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export default async (req, res) => {

Check failure on line 1 in src/supabase/functions/stripeWebhook/index.ts

View workflow job for this annotation

GitHub Actions / test (E2E)

Parameter 'req' implicitly has an 'any' type.
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
const { createClient } = require("@supabase/supabase-js");
const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_SERVICE_ROLE_KEY,
);

const sig = req.headers["stripe-signature"];
let event;

try {
event = stripe.webhooks.constructEvent(
req.rawBody,
sig,
process.env.STRIPE_WEBHOOK_SECRET,
);
} catch (err) {
// Invalid signature, return error response
return res.status(400).send(`Webhook Error: ${err.message}`);
}

// Handle the event
if (event.type === "invoice.payment_succeeded") {
// Update subscription status in your database
const invoice = event.data.object;
const { error } = await supabase
.from("subscriptions")
.update({ status: "active" })
.match({ stripe_subscription_id: invoice.subscription });

if (error) {
console.error("Error updating subscription:", error);
return res.status(500).send("Internal Server Error");
}

// Successful response
return res.status(200).send("Webhook received and processed successfully");
} else {
// Unexpected event type
return res.status(400).send(`Unhandled event type ${event.type}`);
}
};
7 changes: 7 additions & 0 deletions src/supabase/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// initialize Supabase client
import { createClient } from "@supabase/supabase-js";

const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;

export const supabase = createClient(supabaseUrl, supabaseAnonKey);
File renamed without changes.
6 changes: 6 additions & 0 deletions src/views/HomeView.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<script setup lang="ts">
import TheWelcome from "../components/TheWelcome.vue";
import SignIn from "../components/SignIn.vue";
import SignUp from "../components/SignUp.vue";
</script>

<template>
<main>
<TheWelcome />
<div class="flex">
<SignIn />
<SignUp />
</div>
</main>
</template>

0 comments on commit 838e92f

Please sign in to comment.