supaapps-auth 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,10 +3,12 @@ export declare class AuthManager {
3
3
  private readonly authServer;
4
4
  private readonly realmName;
5
5
  private readonly redirectUri;
6
- constructor(authServer: string, realmName: string, redirectUri: string);
6
+ private readonly loginCallback;
7
+ constructor(authServer: string, realmName: string, redirectUri: string, loginCallback: () => void);
7
8
  static getInstance<T>(): AuthManager;
8
9
  private toBase64Url;
9
10
  private generatePKCEPair;
11
+ mustBeLoggedIn(): Promise<boolean>;
10
12
  getLoginWithGoogleUri(): string;
11
13
  isLoggedIn(): Promise<boolean>;
12
14
  getAccessToken(): Promise<string>;
@@ -12,10 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AuthManager = void 0;
13
13
  const crypto_1 = require("crypto");
14
14
  class AuthManager {
15
- constructor(authServer, realmName, redirectUri) {
15
+ constructor(authServer, realmName, redirectUri, loginCallback) {
16
16
  this.authServer = null;
17
17
  this.realmName = null;
18
18
  this.redirectUri = null;
19
+ this.loginCallback = () => { };
19
20
  this.toBase64Url = (base64String) => {
20
21
  return base64String
21
22
  .replace(/\+/g, '-')
@@ -37,6 +38,7 @@ class AuthManager {
37
38
  this.authServer = authServer;
38
39
  this.realmName = realmName;
39
40
  this.redirectUri = redirectUri;
41
+ this.loginCallback = loginCallback;
40
42
  AuthManager.instance = this;
41
43
  }
42
44
  static getInstance() {
@@ -45,6 +47,19 @@ class AuthManager {
45
47
  }
46
48
  return AuthManager.instance;
47
49
  }
50
+ mustBeLoggedIn() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ return new Promise((resolve, reject) => {
53
+ this.isLoggedIn().then((isLoggedIn) => {
54
+ if (!isLoggedIn) {
55
+ this.loginCallback();
56
+ return resolve(false);
57
+ }
58
+ return resolve(true);
59
+ });
60
+ });
61
+ });
62
+ }
48
63
  getLoginWithGoogleUri() {
49
64
  // get or create codeVerifier and codeChallenge from localstorage
50
65
  const { newCodeVerifier, newCodeChallenge } = this.generatePKCEPair();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supaapps-auth",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,10 +9,13 @@ export class AuthManager {
9
9
  private readonly realmName: string | null = null;
10
10
 
11
11
  private readonly redirectUri: string | null = null;
12
- public constructor(authServer: string, realmName: string, redirectUri: string) {
12
+ private readonly loginCallback: () => void = () => {};
13
+
14
+ public constructor(authServer: string, realmName: string, redirectUri: string, loginCallback: () => void) {
13
15
  this.authServer = authServer;
14
16
  this.realmName = realmName;
15
17
  this.redirectUri = redirectUri;
18
+ this.loginCallback = loginCallback;
16
19
  AuthManager.instance = this;
17
20
  }
18
21
 
@@ -46,6 +49,19 @@ export class AuthManager {
46
49
 
47
50
  return { newCodeVerifier, newCodeChallenge };
48
51
  };
52
+
53
+ public async mustBeLoggedIn(): Promise<boolean> {
54
+ return new Promise((resolve, reject) => {
55
+ this.isLoggedIn().then((isLoggedIn) => {
56
+ if (!isLoggedIn) {
57
+ this.loginCallback();
58
+ return resolve(false);
59
+ }
60
+ return resolve(true);
61
+ });
62
+ });
63
+ }
64
+
49
65
  public getLoginWithGoogleUri(): string {
50
66
  // get or create codeVerifier and codeChallenge from localstorage
51
67
  const { newCodeVerifier, newCodeChallenge } = this.generatePKCEPair();