fix typescript errors

This commit is contained in:
George Fitzgibbons 2021-06-30 21:41:50 -04:00
parent 1182ef523d
commit 5799915c0b
3 changed files with 17 additions and 14 deletions

View File

@ -13,8 +13,6 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
const { cookies } = req
const cartId = cookies[config.cartCookie]
const customerToken = cookies[config.customerCookie]
let checkouturl: string
if (!cartId) {
res.redirect('/cart')
return
@ -27,8 +25,14 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
)
const customerId =
customerToken && (await getCustomerId({ customerToken, config }))
//if there is a customer create a jwt token
if (customerId >= 0) {
if (!customerId) {
if (fullCheckout) {
res.redirect(data.checkout_url)
return
}
} else {
const dateCreated = Math.round(new Date().getTime() / 1000)
const payload = {
iss: config.storeApiClientId,
@ -40,18 +44,16 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
channel_id: config.storeChannelId,
redirect_to: data.checkout_url,
}
let token = jwt.sign(payload, config.storeApiClientSecret, {
let token = jwt.sign(payload, config.storeApiClientSecret!, {
algorithm: 'HS256',
})
checkouturl = `${config.storeUrl}/login/token/${token}`
} else {
checkouturl = data.checkout_url
}
let checkouturl = `${config.storeUrl}/login/token/${token}`
console.log('checkouturl', checkouturl)
if (fullCheckout) {
res.redirect(checkouturl)
return
}
}
// TODO: make the embedded checkout work too!
const html = `

View File

@ -1,5 +1,5 @@
import type { GetCustomerIdQuery } from '../../../../schema'
import type { BigcommerceConfig } from '../../..'
import type { GetCustomerIdQuery } from '../../schema'
import type { BigcommerceConfig } from '../'
export const getCustomerIdQuery = /* GraphQL */ `
query getCustomerId {

1
next-env.d.ts vendored
View File

@ -1,2 +1,3 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />