From 2d0634cdc3d00b3e55cf773ff03c7dc841112d36 Mon Sep 17 00:00:00 2001 From: Joe Carstairs <65492573+Sycamost@users.noreply.github.com> Date: Thu, 21 Dec 2023 21:22:47 +0000 Subject: 33 / Users can sign up and log in with WebAuthn (#39) * Installs @vercel/postgres * Installs @simplewebauthn/server * Installs @simplewebauthn/browser * Git-ignores all files starting with .env * Reorganises folders in API * Defines User type * Defines Subscription type * Defines Authenticator type * Sets up table definition file * Can get user from database * Can add user to database * Can get user's current challenge * Can set user's current challenge * Can get user's authenticators from database * Can get authenticator by ID from database * Can add user authenticator to database * Can update authenticator in database * Defines Relying Party information * Can generate registration options * Can verify registration response * Defines registration API endpoint * Defines user API endpoint * Reorganises API functions on frontend * Can access authentication API functions on frontend * Can generate authentication options * Can verify authentication response * Documents the registration flow * Fix dev_csso * Form styling * WIP adds sign up page --- src/scripts/wc/paypal-product-buttons.ts | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'src/scripts') diff --git a/src/scripts/wc/paypal-product-buttons.ts b/src/scripts/wc/paypal-product-buttons.ts index ca06524..b2e7e35 100644 --- a/src/scripts/wc/paypal-product-buttons.ts +++ b/src/scripts/wc/paypal-product-buttons.ts @@ -1,6 +1,7 @@ -import { type PayPalNamespace, loadScript } from '@paypal/paypal-js'; +import type { PayPalNamespace } from '@paypal/paypal-js'; -const backendUrl = '/api'; +import { loadScript } from '@paypal/paypal-js'; +import * as api from '$lib/api'; class PaypalProductButtons extends HTMLElement { constructor() { @@ -67,18 +68,10 @@ class PaypalProductButtons extends HTMLElement { return constructButtons({ // This function is called to set up the transaction details without actually carrying it out async createOrder() { - const body = JSON.stringify({ - productDescription, - shortDescription, - totalPrice, - }); - const headers = { - 'Content-Type': 'application/json', - }; let response: Response; try { - response = await fetch(`${backendUrl}/order`, { method: 'POST', body, headers }); + response = await api.createOrder({ productDescription, shortDescription, totalPrice }); } catch (err) { throw new Error(`Failed to create order. ${err}`); } @@ -100,17 +93,9 @@ class PaypalProductButtons extends HTMLElement { // This function is called after payment is confirmed async onApprove(data) { - const body = JSON.stringify({ - id: data.orderID, - isApproved: true, - }); - const headers = { - 'Content-Type': 'application/json', - }; - let response: Response; try { - response = await fetch(`${backendUrl}/order`, { method: 'PATCH', body, headers }); + response = await api.captureOrder(data.orderID); } catch (err) { throw new Error(`Failed to capture order. ${err}`); } -- cgit v1.2.3