Use base64 library to encode basic auth 🤦
Buffer being not enabled on Vercel Edge Functions
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user