Bypass Shopify auth when developing Shopify apps locally with Koa & Next JS?

Viewed 968

So I'm following https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react but ever since I ngrok'd it's too slow.

Is there any way I can develop locally? I know Shopify is a hosted solution but ngrok makes it way too slow for me.

I'm from India & I think the servers are from US & it's so slow that it takes literally 5 mins & sometimes it doesn't even load properly at all.

Here's my current server.js:

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

dotenv.config()

const { PORT, NODE_ENV, SHOPIFY_API_SECRET_KEY, SHOPIFY_API_KEY } = process.env

const port = parseInt(PORT, 10) || 3000
const dev = NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare().then(() => {
    const server = new Koa()
    server.use(session({ secure: true, sameSite: 'none' }, server))
    server.keys = [SHOPIFY_API_SECRET_KEY]
    server.use(
        createShopifyAuth({
            apiKey: SHOPIFY_API_KEY,
            secret: SHOPIFY_API_SECRET_KEY,
            scopes: ['read_products'],
            afterAuth(ctx) {
                const { shop, accessToken } = ctx.session
                ctx.cookies.set('shopOrigin', shop, {
                    httpOnly: false,
                    secure: true,
                    sameSite: 'none',
                })
                ctx.redirect('/')
            },
        })
    )

    server.use(verifyRequest())
    server.use(async (ctx) => {
        await handle(ctx.req, ctx.res)
        ctx.respond = false
        ctx.res.statusCode = 200
        return
    })
    server.listen(port, () => {
        console.log(`> Ready on http://localhost:${port}`)
    })
})

Can I set the dev variable somewhere & bypass Shopify auth (Idk much about koa) to code my app locally & then check the final result on Shopify app store?

I even tried serveo, lynk, sish & many other ngrok alternatives. None of them worked. serveo did until it didn't. So I gotta use 8 hours of ngrok but any other solutions are appreciated.

0 Answers
Related