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.
- package/dist/AuthManager.js +16 -5
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/AuthManager.ts +18 -4
- package/src/types.ts +1 -1
package/dist/AuthManager.js
CHANGED
|
@@ -115,13 +115,24 @@ class AuthManager {
|
|
|
115
115
|
}
|
|
116
116
|
isLoggedIn() {
|
|
117
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
package/package.json
CHANGED
package/src/AuthManager.ts
CHANGED
|
@@ -158,12 +158,26 @@ export class AuthManager {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
public async isLoggedIn(): Promise<boolean> {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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(
|