Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript errors when defining custom session store #234

Closed
urbanhusky opened this issue May 12, 2021 · 7 comments
Closed

TypeScript errors when defining custom session store #234

urbanhusky opened this issue May 12, 2021 · 7 comments
Labels
bug Something isn't working closed:stale Issue or PR has not seen activity recently

Comments

@urbanhusky
Copy link

I'm trying to use a custom session store, but I get TypeScript errors.

import express from 'express';
import { auth } from 'express-openid-connect';
import session from 'express-session';
import createMemoryStore from 'memorystore';


const MemoryStore = createMemoryStore(session);
const app = express();
app.use(
  auth({
    // …
    session: {
      store: new MemoryStore({
        checkPeriod: 86400000,
      }),
    },
  }),
);

TS2322: Type 'MemoryStore' is not assignable to type 'SessionStore'.
  Types of property 'get' are incompatible.
    Type '(sid: string, callback: (err: any, session?: SessionData | null | undefined) => void) => void' is not assignable to type '(sid: string, callback: (err: any, session?: SessionStorePayload | null | undefined) => void) => void'.
      Types of parameters 'callback' and 'callback' are incompatible.
        Types of parameters 'session' and 'session' are incompatible.
          Type 'SessionData | null | undefined' is not assignable to type 'SessionStorePayload | null | undefined'.
            Type 'SessionData' is missing the following properties from type 'SessionStorePayload': header, data

I can circumvent this error by casting MemoryStore to any, but that's not really a solution.

store: new MemoryStore({
  checkPeriod: 86400000,
}) as any,
@adamjmcgrath adamjmcgrath added the bug Something isn't working label May 14, 2021
@adamjmcgrath
Copy link
Member

Hi @urbanhusky - thanks for raising this, we'll take a look at it before the next release.

In the meantime, please continue to use the workaround you described

@HartS
Copy link

HartS commented May 15, 2021

I can circumvent this error by casting MemoryStore to any, but that's not really a solution.

I had this same issue with PrismaSessionStore; I solved it by using a type assertion to the SessionStore interface from express-openid-connect

@stale
Copy link

stale bot commented Aug 24, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

@stale stale bot added the closed:stale Issue or PR has not seen activity recently label Aug 24, 2021
@htadeusiak
Copy link

htadeusiak commented Aug 25, 2021

I'm running into this issue too with Redis, any update?

@stale stale bot removed the closed:stale Issue or PR has not seen activity recently label Aug 25, 2021
@HartS
Copy link

HartS commented Aug 25, 2021

I'm not involved with the project, but in case my previous comment wasn't detailed enough, I think this is the best workaround until they have a fix (for this example, I use the PrismaSessionStore by https://github.com/kleydon/prisma-session-store):

import { auth, SessionStore } from 'express-openid-connect';
import { PrismaSessionStore } from '@quixo3/prisma-session-store';

const AdminSessionStore = new PrismaSessionStore(prisma, {
  ...settings
});

const OpenIdMiddleware = auth({
  authRequired: ...,
  issuerBaseURL: ...,
  baseURL: ...,
  clientID: ...,
  secret: ...,
  session: {
    store: AdminSessionStore as SessionStore,
    name: 'myoidcname',
  }
});

@HartS
Copy link

HartS commented Sep 9, 2021

I'm not sure which dependency changing broke my workaround, but I do now have to use as any to get this to work

@stale
Copy link

stale bot commented Dec 9, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

@stale stale bot added the closed:stale Issue or PR has not seen activity recently label Dec 9, 2021
@stale stale bot closed this as completed Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working closed:stale Issue or PR has not seen activity recently
Projects
None yet
Development

No branches or pull requests

4 participants