diff --git a/src/lib/prisma-session-store.ts b/src/lib/prisma-session-store.ts index f8f0436..7b9fc05 100755 --- a/src/lib/prisma-session-store.ts +++ b/src/lib/prisma-session-store.ts @@ -154,6 +154,13 @@ export class PrismaSessionStore extends Store { this.invalidConnection = true; } + /** + * Enables store, used when prisma can be connected to + */ + private enable(): void { + this.invalidConnection = false; + } + /** * Returns if the connect is valid or not, logging an error if it is not. */ @@ -161,13 +168,18 @@ export class PrismaSessionStore extends Store { await ( this.prisma?.$connect?.() ?? Promise.reject(new Error('Could not connect')) - ).catch(() => { - this.disable(); - this.stopInterval(); - this.logger.error(dedent`Could not connect to 'Session' model in Prisma. + ) + .then(() => { + this.enable(); + this.startInterval(); + }) + .catch(() => { + this.disable(); + this.stopInterval(); + this.logger.error(dedent`Could not connect to 'Session' model in Prisma. Please make sure that prisma is setup correctly, that 'Session' model exists, and that your migrations are current. For more information check out https://github.com/kleydon/prisma-session-store`); - }); + }); return !this.invalidConnection; } @@ -499,6 +511,8 @@ export class PrismaSessionStore extends Store { * Start an interval to prune expired sessions */ public startInterval(onIntervalError?: (err: unknown) => void): void { + if (this.checkInterval) return; + const ms = this.options.checkPeriod; if (typeof ms === 'number' && ms !== 0) { this.stopInterval();