From 3ca8ed0d06102a6820183cfa629e2dc8e498b078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Sun, 18 Sep 2022 18:52:02 +0200 Subject: [PATCH] =?UTF-8?q?Use=20base64=20library=20to=20encode=20basic=20?= =?UTF-8?q?auth=20=F0=9F=A4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Buffer being not enabled on Vercel Edge Functions --- package.json | 1 + pnpm-lock.yaml | 6 ++++++ src/routes/shop/+layout.server.ts | 3 ++- src/routes/shop/+page.server.ts | 3 ++- src/routes/shop/[type]-[name]/+page.server.ts | 3 ++- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 4c146a8..ea479b2 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@sveltejs/kit": "^1.0.0-next.484", "@typescript-eslint/eslint-plugin": "^5.37.0", "@typescript-eslint/parser": "^5.37.0", + "base-64": "^1.0.0", "browserslist": "^4.21.4", "cssnano": "^5.1.13", "eslint": "^8.23.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9a24287..8ab101f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,7 @@ specifiers: '@sveltejs/kit': ^1.0.0-next.484 '@typescript-eslint/eslint-plugin': ^5.37.0 '@typescript-eslint/parser': ^5.37.0 + base-64: ^1.0.0 browserslist: ^4.21.4 cssnano: ^5.1.13 dayjs: ^1.11.5 @@ -51,6 +52,7 @@ devDependencies: '@sveltejs/kit': 1.0.0-next.484_svelte@3.50.1+vite@3.1.2 '@typescript-eslint/eslint-plugin': 5.37.0_22c5fnooleyfkzrkkgdmel5kmi '@typescript-eslint/parser': 5.37.0_irgkl5vooow2ydyo6aokmferha + base-64: 1.0.0 browserslist: 4.21.4 cssnano: 5.1.13_postcss@8.4.16 eslint: 8.23.1 @@ -792,6 +794,10 @@ packages: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} dev: true + /base-64/1.0.0: + resolution: {integrity: sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg==} + dev: true + /binary-extensions/2.2.0: resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==} engines: {node: '>=8'} diff --git a/src/routes/shop/+layout.server.ts b/src/routes/shop/+layout.server.ts index 0d55974..e1df03e 100644 --- a/src/routes/shop/+layout.server.ts +++ b/src/routes/shop/+layout.server.ts @@ -1,5 +1,6 @@ import { error } from '@sveltejs/kit' import type { PageServerLoad } from './$types' +import base64 from 'base-64' import { fetchAPI } from '$utils/api' import { PUBLIC_SWELL_STORE_ID } from '$env/static/public' import { SWELL_API_TOKEN, SWELL_API_ENDPOINT } from '$env/static/private' @@ -58,7 +59,7 @@ export const load: PageServerLoad = async () => { */ const shopProductsRes: any = await fetch(`${SWELL_API_ENDPOINT}/products`, { headers: { - Authorization: `Basic ${Buffer.from(`${PUBLIC_SWELL_STORE_ID}:${SWELL_API_TOKEN}`).toString('base64')}` + Authorization: `Basic ${base64.encode(`${PUBLIC_SWELL_STORE_ID}:${SWELL_API_TOKEN}`)}` }, }) const shopProducts = await shopProductsRes.json() diff --git a/src/routes/shop/+page.server.ts b/src/routes/shop/+page.server.ts index f9486b6..684600d 100644 --- a/src/routes/shop/+page.server.ts +++ b/src/routes/shop/+page.server.ts @@ -1,5 +1,6 @@ import { error } from '@sveltejs/kit' import type { PageServerLoad } from './$types' +import base64 from 'base-64' import { fetchAPI } from '$utils/api' import { getRandomItem } from '$utils/functions' import { PUBLIC_SWELL_STORE_ID } from '$env/static/public' @@ -42,7 +43,7 @@ export const load: PageServerLoad = async ({}) => { // Fetch Swell API for product const shopProductRes: any = await fetch(`${SWELL_API_ENDPOINT}/products/${randomPoster.product_id}`, { headers: { - Authorization: `Basic ${Buffer.from(`${PUBLIC_SWELL_STORE_ID}:${SWELL_API_TOKEN}`).toString('base64')}` + Authorization: `Basic ${base64.encode(`${PUBLIC_SWELL_STORE_ID}:${SWELL_API_TOKEN}`)}` }, }) const shopProduct = await shopProductRes.json() diff --git a/src/routes/shop/[type]-[name]/+page.server.ts b/src/routes/shop/[type]-[name]/+page.server.ts index 6b51f0c..0360321 100644 --- a/src/routes/shop/[type]-[name]/+page.server.ts +++ b/src/routes/shop/[type]-[name]/+page.server.ts @@ -1,5 +1,6 @@ import { error } from '@sveltejs/kit' import type { PageServerLoad } from './$types' +import base64 from 'base-64' import { fetchAPI } from '$utils/api' import { PUBLIC_SWELL_STORE_ID } from '$env/static/public' import { SWELL_API_TOKEN, SWELL_API_ENDPOINT } from '$env/static/private' @@ -39,7 +40,7 @@ export const load: PageServerLoad = async ({ params }) => { // Fetch Swell API for product const shopProductRes: any = await fetch(`${SWELL_API_ENDPOINT}/products/${poster.product_id}`, { headers: { - Authorization: `Basic ${Buffer.from(`${PUBLIC_SWELL_STORE_ID}:${SWELL_API_TOKEN}`).toString('base64')}` + Authorization: `Basic ${base64.encode(`${PUBLIC_SWELL_STORE_ID}:${SWELL_API_TOKEN}`)}` }, }) const shopProduct = await shopProductRes.json()