supaapps-auth 2.0.0 → 2.1.0

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.
@@ -115,13 +115,24 @@ class AuthManager {
115
115
  }
116
116
  isLoggedIn() {
117
117
  return __awaiter(this, void 0, void 0, function* () {
118
- try {
119
- yield this.checkAccessToken();
120
- return true;
121
- }
122
- catch (error) {
118
+ const accessToken = localStorage.getItem('access_token');
119
+ const refreshToken = localStorage.getItem('refresh_token');
120
+ // If either token is missing, user is not logged in
121
+ if (!accessToken || !refreshToken) {
123
122
  return false;
124
123
  }
124
+ // If access token is expired, try to refresh
125
+ if (this.isTokenExpired(accessToken)) {
126
+ try {
127
+ yield this.refreshAccessToken();
128
+ return true;
129
+ }
130
+ catch (_a) {
131
+ return false;
132
+ }
133
+ }
134
+ // If access token is valid
135
+ return true;
125
136
  });
126
137
  }
127
138
  getAccessToken() {
package/dist/types.d.ts CHANGED
@@ -26,7 +26,7 @@ export interface AuthManagerEvent {
26
26
  user?: UserTokenPayload;
27
27
  }
28
28
  export interface PlatformCheckResponse {
29
- platform: Platforms[];
29
+ platforms: Platforms[];
30
30
  }
31
31
  export declare enum Platforms {
32
32
  PASSWORD = "password",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supaapps-auth",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -158,12 +158,26 @@ export class AuthManager {
158
158
  }
159
159
 
160
160
  public async isLoggedIn(): Promise<boolean> {
161
- try {
162
- await this.checkAccessToken();
163
- return true;
164
- } catch (error) {
161
+ const accessToken = localStorage.getItem('access_token');
162
+ const refreshToken = localStorage.getItem('refresh_token');
163
+
164
+ // If either token is missing, user is not logged in
165
+ if (!accessToken || !refreshToken) {
165
166
  return false;
166
167
  }
168
+
169
+ // If access token is expired, try to refresh
170
+ if (this.isTokenExpired(accessToken)) {
171
+ try {
172
+ await this.refreshAccessToken();
173
+ return true;
174
+ } catch {
175
+ return false;
176
+ }
177
+ }
178
+
179
+ // If access token is valid
180
+ return true;
167
181
  }
168
182
 
169
183
  public async getAccessToken(
package/src/types.ts CHANGED
@@ -30,7 +30,7 @@ export interface AuthManagerEvent {
30
30
  }
31
31
 
32
32
  export interface PlatformCheckResponse {
33
- platform: Platforms[];
33
+ platforms: Platforms[];
34
34
  }
35
35
 
36
36
  export enum Platforms {