Skip to content

After Authentication Job

Tyler King edited this page Aug 16, 2017 · 2 revisions

For some apps, you may want something to fire after installation or authentication of a shop to the app. Some usecases:

  • Sending a welcome email to the shop owner
  • Configuring some extra database needs
  • Uploading assets to a theme on install

Setup

First, open config/shopify-app.php in your Laravel directory and search for After Authenticate Job in that file so you're at the right location.

Creating a job

php artisan make:job {YourJobName}

Example:

php artisan make:job AfterAuthenticateJob

Adding the job

In config/shopify-app.php you'll find something like:

    'after_authenticate_job' => [
        'job' => '',
        'inline' => false,
    ],

Simply replace job with the namespace to your job class. Example: \App\Jobs\AfterAuthenticateJob::class.

Inline Option

The inline option is for running the job immediately (inline) or dispatching it to a queue to run later. Most use cases you will leave this as false to dispatch to a queue. If you need to run something before the user accesses your app (like database setup, asset installs) that simply can't wait before the screen loads, then set inline to be true to run immediately.

Notes

The job you configure will run every time a shop installs the app and it will run every time they access the app through Shopify in a new session. If you wish this job to run only once on install, then you will need to track this on your own in the job, through something like the database to keep track if the job ran for that specific shop.