Why my server still trying to redirect to /auth after I set all of these prefix?

Highlighted
Tourist
6 0 2

It happens every time when a user without any cookies about shopify's authentication try to open my app.

As asked in the title, help me please! Here's my server.js.

require("isomorphic-fetch");
const dotenv = require("dotenv");
const Koa = require("koa");
const next = require("next");
const mount = require("koa-mount");
const { default: createShopifyAuth } = require("@shopify/koa-shopify-auth");
const { verifyRequest } = require("@shopify/koa-shopify-auth");
const session = require("koa-session");

dotenv.config();
const { default: graphQLProxy } = require("@shopify/koa-shopify-graphql-proxy");
const { ApiVersion } = require("@shopify/koa-shopify-graphql-proxy");

const port = parseInt(process.env.PORT, 10) || 7001;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();

const { SHOPIFY_API_SECRET_KEY, SHOPIFY_API_KEY } = process.env;

app.prepare().then(() => {
const server = new Koa();
server.use(session(server));
server.keys = [SHOPIFY_API_SECRET_KEY];
server.use(
createShopifyAuth({
prefix: "/thirdparty/shopify/shineapp",
apiKey: SHOPIFY_API_KEY,
secret: SHOPIFY_API_SECRET_KEY,
scopes: ["read_products", "write_products"],
afterAuth(ctx) {
const { shop, accessToken } = ctx.session;
ctx.cookies.set("shopOrigin", shop, { httpOnly: false });

ctx.redirect("/thirdparty/shopify/shineapp/index");
}
})
);

server.use(
mount(
"/thirdparty/shopify/shineapp",
graphQLProxy({ version: ApiVersion.October19 })
)
);
server.use(
verifyRequest({
authRoute: "/thirdparty/shopify/shineapp/auth",
fallbackRoute: "/thirdparty/shopify/shineapp/auth"
})
);
server.use(async ctx => {
await handle(ctx.req, ctx.res);
ctx.respond = false;
ctx.res.statusCode = 200;
});

server.listen(port, () => {
console.log(`> Ready on https://localhost:${port}`);
});
});
1 Like
Highlighted
Tourist
6 0 2

Related issue is found. https://github.com/Shopify/quilt/issues/1148 

It seems that I also stuck on setting enable-cookie's prefix.

Looking forward for further improvements on @shopify/koa-shopify-auth

0 Likes
Highlighted
Tourist
6 0 1

Are there any updates on this?

 

I found that if I get redirected to the URL without the prefix and then I try to install/authorize the app again then I actually get redirected with the prefix. Do you have that same behavior?

0 Likes