Source

lib/client/SessionClient.ts

  1. import { Client } from "./Client";
  2. import { SessionCheckResponse } from "../Dto";
  3. import { TechnicalError } from "../Errors";
  4. /**
  5. * A class that handles communication with the Hanko API for the purposes
  6. * of sessions.
  7. *
  8. * @constructor
  9. * @category SDK
  10. * @subcategory Clients
  11. * @extends {Client}
  12. */
  13. export class SessionClient extends Client {
  14. /**
  15. * Checks if the current session is still valid.
  16. *
  17. * @return {Promise<SessionCheckResponse>}
  18. * @throws {TechnicalError}
  19. */
  20. async validate(): Promise<SessionCheckResponse> {
  21. const response = await this.client.get("/sessions/validate");
  22. if (!response.ok) {
  23. throw new TechnicalError();
  24. }
  25. return await response.json();
  26. }
  27. }