npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sveltekit-shopify-auth

v1.6.3

Published

A handler to authenticate a SvelteKit application with Shopify

Downloads

8

Readme

sveltekit-shopify-auth

License: MIT npm version

A handler to authenticate a SvelteKit application with Shopify.

Based entirely on to @shopify/koa-shopify-auth

Installation

$ yarn add svelte-shopify-auth

Usage

This package exposes createHandler and verifyRequest as named exports.

// inside your hook handle function. See https://kit.svelte.dev/docs/hooks#handle
import { createHandler } from "sveltekit-shopify-auth"

const authHandler = createHandler(config)

const authResponse = await authHandler(event)
if (authResponse) {
  return authResponse
}

createHandler

Handles the auth process of shopify. A config object should be passed to this function.

import { createHandler } from "sveltekit-shopify-auth"

const authHandler = createHandler({
  // if specified, mounts the routes off of the given path
  // eg. /shopify/auth, /shopify/auth/callback
  // defaults to ''
  prefix: '/shopify',
  // set access mode, default is 'online'
  accessMode: 'offline',
  // callback for when auth is completed
  afterAuth (result: AuthValidationResult) {
    const { shop, accessToken, scope } = result.session
    const host = result.host

    console.log('We did it! 🥳', accessToken);

    // Redirect to our app 🎉
    return new Response(null, {
      status : 301,
      headers: {
        location: `/?shop=${ shop }&host=${ host }`,
      },
    })
  },
})

verifyRequest

Verifies requests before letting them further in the chain.

import { verifyRequest } from "sveltekit-shopify-auth"

const verifyFn = verifyRequest({returnHeader: true})
const response = await verifyFn(config, event)
if (response.status !== 200) {
  return response
}

Example app

This example will enable you to quickly set up the backend for a working development app. Please read the Gotchas session below to make sure you are ready for production use.


## Gotchas

### Session

The provided `MemorySessionStorage` class may not be scalable for production use. You can implement
your own strategy by creating a class that implements a few key methods. Learn more
about [how the Shopify Library handles sessions](https://github.com/Shopify/shopify-node-api/blob/main/docs/issues.md#notes-on-session-handling)
.

### Testing locally

By default this app requires that you use a `myshopify.com` host in the `shop` parameter. You can
modify this to test against a local/staging environment via the `myShopifyDomain` option
to `createHandler` (e.g. `myshopify.io`).