fix typescript errors

This commit is contained in:
George Fitzgibbons 2021-06-30 21:12:20 -04:00
parent 4ff10864bb
commit 701c626597
4 changed files with 919 additions and 915 deletions

View File

@ -25,10 +25,19 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
method: 'POST', method: 'POST',
} }
) )
const customerId = const customerId: string =
customerToken && (await getCustomerId({ customerToken, config })) (customerToken && (await getCustomerId({ customerToken, config }))) ?? ''
console.log('customerId', customerId)
console.log('check', customerId == 'undefined')
//if there is a customer create a jwt token //if there is a customer create a jwt token
if (customerId >= 0) { if (customerId == 'undefined') {
if (fullCheckout) {
res.redirect(data.checkout_url)
return
}
} else {
const dateCreated = Math.round(new Date().getTime() / 1000) const dateCreated = Math.round(new Date().getTime() / 1000)
const payload = { const payload = {
iss: config.storeApiClientId, iss: config.storeApiClientId,
@ -40,17 +49,15 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
channel_id: config.storeChannelId, channel_id: config.storeChannelId,
redirect_to: data.checkout_url, redirect_to: data.checkout_url,
} }
let token = jwt.sign(payload, config.storeApiClientSecret, { let token = jwt.sign(payload, config.storeApiClientSecret!, {
algorithm: 'HS256', algorithm: 'HS256',
}) })
checkouturl = `${config.storeUrl}/login/token/${token}` checkouturl = `${config.storeUrl}/login/token/${token}`
} else {
checkouturl = data.checkout_url
}
if (fullCheckout) { if (fullCheckout) {
res.redirect(checkouturl) res.redirect(checkouturl)
return return
}
} }
// TODO: make the embedded checkout work too! // TODO: make the embedded checkout work too!

View File

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

1
next-env.d.ts vendored
View File

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

1802
yarn.lock

File diff suppressed because it is too large Load Diff