Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Async/Await or Promise in afterAuth #84

Open
jstoeffler opened this issue May 26, 2018 · 1 comment
Open

Async/Await or Promise in afterAuth #84

jstoeffler opened this issue May 26, 2018 · 1 comment

Comments

@jstoeffler
Copy link

Hi,

Thanks for this great package!
I'm working in an app, and I'm trying to save the store data (the store domain and the access token of the user) in a database.

I thought the best way to do this is in afterAuth, because you want to do this as early as possible in the process. The problem is that the database APIS are Promise/Async-Await based, and it seems like it's not possible to wait for afterAuth to return the redirection.

Perhaps my design is bad, or perhaps there's a way to combine afterAuth with an async middleware? Or is this something which is not supported?

@janfabian
Copy link

Hi, you can use async promise in afterAuth parameter.

Example:

const shopifyConfig = {
    host: config.shopify.host,
    apiKey: config.shopify.apiKey,
    secret: config.shopify.secret,
    scope: ['read_products, read_inventory'],
    shopStore: new MongoStrategy(),
    async afterAuth(request, response) {
        const { session: { accessToken, shop } } = request;

        slackNotification(shop);
        await registerAppShop(shop);
        await registerShopifyShop(shop, accessToken);
        await startCalculateVariantStatistics(shop, accessToken);
        await registerWebhooks(shop, accessToken);
        return response.redirect('/');
    },
};

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants