🚨 Announcing Vendure v2 Beta

SessionService

SessionService

Contains methods relating to Session entities.

Signature

class SessionService implements EntitySubscriberInterface {
  constructor(connection: TransactionalConnection, configService: ConfigService, orderService: OrderService)
  async createNewAuthenticatedSession(ctx: RequestContext, user: User, authenticationStrategyName: string) => Promise<AuthenticatedSession>;
  async createAnonymousSession() => Promise<CachedSession>;
  async getSessionFromToken(sessionToken: string) => Promise<CachedSession | undefined>;
  serializeSession(session: AuthenticatedSession | AnonymousSession) => CachedSession;
  async setActiveOrder(ctx: RequestContext, serializedSession: CachedSession, order: Order) => Promise<CachedSession>;
  async unsetActiveOrder(ctx: RequestContext, serializedSession: CachedSession) => Promise<CachedSession>;
  async setActiveChannel(serializedSession: CachedSession, channel: Channel) => Promise<CachedSession>;
  async deleteSessionsByUser(ctx: RequestContext, user: User) => Promise<void>;
  async deleteSessionsByActiveOrderId(ctx: RequestContext, activeOrderId: ID) => Promise<void>;
}

Implements

  • EntitySubscriberInterface

Members

constructor

method
type:
(connection: TransactionalConnection, configService: ConfigService, orderService: OrderService) => SessionService

createNewAuthenticatedSession

async method
type:
(ctx: RequestContext, user: User, authenticationStrategyName: string) => Promise<AuthenticatedSession>
Creates a new AuthenticatedSession. To be used after successful authentication.

createAnonymousSession

async method
type:
() => Promise<CachedSession>
Create an AnonymousSession and caches it using the configured SessionCacheStrategy, and returns the cached session object.

getSessionFromToken

async method
type:
(sessionToken: string) => Promise<CachedSession | undefined>
Returns the cached session object matching the given session token.

serializeSession

method
Serializes a Session instance into a simplified plain object suitable for caching.

setActiveOrder

async method
type:
(ctx: RequestContext, serializedSession: CachedSession, order: Order) => Promise<CachedSession>
Sets the activeOrder on the given cached session object and updates the cache.

unsetActiveOrder

async method
type:
(ctx: RequestContext, serializedSession: CachedSession) => Promise<CachedSession>
Clears the activeOrder on the given cached session object and updates the cache.

setActiveChannel

async method
type:
(serializedSession: CachedSession, channel: Channel) => Promise<CachedSession>
Sets the activeChannel on the given cached session object and updates the cache.

deleteSessionsByUser

async method
type:
(ctx: RequestContext, user: User) => Promise<void>
Deletes all existing sessions for the given user.

deleteSessionsByActiveOrderId

async method
type:
(ctx: RequestContext, activeOrderId: ID) => Promise<void>
Deletes all existing sessions with the given activeOrder.