4.0.5 • Published 16 days ago

@shopify/shopify-app-session-storage-prisma v4.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
16 days ago

Session Storage Adapter for Prisma

This package implements the SessionStorage interface that works with an instance of Prisma.

Session storage for prisma requires a schema.prisma with a Session table with at-least the following columns:

model Session {
  id          String    @id
  shop        String
  state       String
  isOnline    Boolean   @default(false)
  scope       String?
  expires     DateTime?
  accessToken String
  userId      BigInt?
}

!WARNING Some DB adapters adapters may set a maximum length for the String type by default, please ensure your fields allow for long enough strings. See https://www.prisma.io/docs/orm/reference/prisma-schema-reference#string for more information

You can then instantiate and use PrismaSessionStorage like so:

import {shopifyApp} from '@shopify/shopify-app-express';
import {PrismaSessionStorage} from '@shopify/shopify-app-session-storage-prisma';
import {PrismaClient} from '@prisma/client';

const prisma = new PrismaClient();
const storage = new PrismaSessionStorage(prisma);

const shopify = shopifyApp({
  sessionStorage: storage,
  // ...
});

Note: If you use SQLite with Prisma note that sqlite is a local, file-based SQL database. It persists all tables to a single file on your local disk. As such, it’s simple to set up and is a great choice for getting started with Shopify App development. However, it won’t work when your app getting scaled across multiple instances because they would each create their own database.

If you prefer to use your own implementation of a session storage mechanism that is compatible with the @shopify/shopify-app-express package, see the implementing session storage guide.

Options

You can also pass in some optional flags to tweak the behavior of the adapter.

Custom table name

You can pass in the tableName option if you want to use a different table name in your schema. For example:

const storage = new PrismaSessionStorage(prisma, {
  tableName: 'MyCustomSession',
});

Troubleshooting

If there is an issue with your schema that prevents it from finding the Session table, this package will throw a MissingSessionTableError. Some common reasons for that are:

  1. The database was not migrated.
  2. The Session table above was not added to the schema.
  3. The table is in the schema, but isn't named Session.

Here are some possible solutions for this issue:

  1. Ensure you've run the migrate command to apply the schema.
  2. Ensure you've copied the schema above into your prisma.schema file.
  3. If you've made changes to the table, make sure it's still called Session.
4.0.5

16 days ago

4.0.4

24 days ago

4.0.3

1 month ago

4.0.2

2 months ago

4.0.1

3 months ago

4.0.0

3 months ago

3.0.0

4 months ago

2.0.3

4 months ago

2.0.2

5 months ago

1.1.1

8 months ago

1.0.2

10 months ago

1.1.0

8 months ago

1.0.1

10 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

10 months ago

2.0.1

7 months ago

2.0.0

7 months ago

1.0.0

11 months ago

1.0.0-rc.3

12 months ago

1.0.0-rc.2

1 year ago

1.0.0-rc.1

1 year ago

1.0.0-rc.0

1 year ago