Closed magicspon closed 2 years ago
They have never worked for me. I'm actually just circling back to this because I thought maybe I could make some headway here, but I'm stumped.
I believe this may be a duplicate of https://github.com/vercel/commerce/issues/273
I just solved the problem for myself. There is an additional cookie Shopper-Pref
that needs to be set at login.
I changed the async function login(){...}
definition in the file framework/bigcommerce/auth/login.ts (lines 32-71)
to the following:
async function login({
query = loginMutation,
variables,
res: response,
config,
}: {
query?: string
variables: LoginVariables
res: ServerResponse
config?: BigcommerceConfig
}): Promise<LoginResult> {
config = getConfig(config)
const { data, res } = await config.fetch<RecursivePartial<LoginMutation>>(
query,
{ variables }
)
// Set-Cookie returns several cookies, we want SHOP_TOKEN and Shopper-pref
let shopToken = getCookie(res.headers.get('Set-Cookie'), 'SHOP_TOKEN');
let prefToken = getCookie(res.headers.get('Set-Cookie'), 'Shopper-Pref');
if (shopToken && typeof shopToken === 'string') {
// In development, don't set a secure shopToken or the browser will ignore it
if (process.env.NODE_ENV !== 'production') {
shopToken = shopToken.replace(/; Secure/gi, '')
shopToken = shopToken.replace(/; SameSite=none/gi, '; SameSite=lax')
}
response.setHeader(
'Set-Cookie',
concatHeader(response.getHeader('Set-Cookie'), shopToken)!
)
response.setHeader(
'Set-Cookie',
concatHeader(response.getHeader('Set-Cookie'), `${prefToken}`)!
)
}
return {
result: data.login?.result,
}
}
@clockelliptic Take a look at the fix here: https://github.com/bigcommerce/storefront-data-hooks/pull/62 you'll want to "Set the cookie at TLD to make it accessible on subdomains" You'll need this otherwise when a user goes to the checkout they will be logged out.
I think this issue might be linked https://github.com/vercel/commerce/issues/531
Looks like this has been solved already!
Login has suddenly stopped working.
Steps to reproduce
If you try logging in with the incorrect details, you get an error message, as expected.
I'm not sure where the issue has come from. My store has been working, I've made zero updates in the last 46 days. And now suddenly it's stopped working.
Any thoughts?