@omerlo/omerlo-webkit 0.0.34 → 0.0.35

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.
@@ -5,11 +5,9 @@ export async function loadUserSession(f, cookies) {
5
5
  if (isAuthenticated(cookies)) {
6
6
  userSession.authenticated = true;
7
7
  try {
8
- const userInfo = await useReader(f)
9
- .userInfo()
10
- .then((resp) => resp.data);
11
- userSession.verified = true;
12
- userSession.user = userInfo;
8
+ const userInfo = await useReader(f).userInfo();
9
+ userSession.verified = userInfo.ok;
10
+ userSession.user = userInfo.data;
13
11
  }
14
12
  catch (_e) {
15
13
  userSession.verified = false;
@@ -22,6 +20,7 @@ export function isAuthenticated(cookies) {
22
20
  }
23
21
  const accessTokenCookieName = 'access_token';
24
22
  const refreshTokenCookieName = 'refresh_token';
23
+ const THREE_MONTH = 90 * 24 * 60 * 60;
25
24
  export function setAuthorizationCookies(cookies, token) {
26
25
  cookies.set('logged_in', 'true', { path: '/', httpOnly: false });
27
26
  cookies.set(accessTokenCookieName, token.accessToken, {
@@ -29,7 +28,11 @@ export function setAuthorizationCookies(cookies, token) {
29
28
  path: '/',
30
29
  maxAge: token.expiresIn - 60
31
30
  });
32
- cookies.set(refreshTokenCookieName, token.refreshToken, { httpOnly: true, path: '/' });
31
+ cookies.set(refreshTokenCookieName, token.refreshToken, {
32
+ httpOnly: true,
33
+ path: '/',
34
+ maxAge: THREE_MONTH
35
+ });
33
36
  }
34
37
  export function clearAuthorizationCookies(cookies) {
35
38
  cookies.delete(accessTokenCookieName, { path: '/' });
@@ -80,8 +83,7 @@ async function refreshApplicationToken() {
80
83
  const token = await refresh(applicationToken.refreshToken);
81
84
  applicationToken.accessToken = token.accessToken;
82
85
  applicationToken.refreshToken = token.refreshToken;
83
- const date = new Date();
84
- const timestamps = date.setSeconds(date.getSeconds() + token.expiresIn - 60);
86
+ const timestamps = new Date().getTime() + (token.expiresIn - 60) * 1000;
85
87
  applicationToken.expiredAt = timestamps;
86
88
  applicationToken.refreshErrorCounter = 0;
87
89
  }
@@ -98,12 +100,18 @@ async function refreshApplicationToken() {
98
100
  })();
99
101
  return refreshingPromise;
100
102
  }
103
+ let newTokenPromise = null;
101
104
  async function newApplicationToken() {
102
- const token = await getAnonymousToken('application');
103
- applicationToken.init = true;
104
- applicationToken.accessToken = token.accessToken;
105
- applicationToken.refreshToken = token.refreshToken;
106
- const date = new Date();
107
- const timestamps = date.setSeconds(date.getSeconds() + token.expiresIn - 60);
108
- applicationToken.expiredAt = timestamps;
105
+ if (newTokenPromise) {
106
+ return newTokenPromise;
107
+ }
108
+ newTokenPromise = (async () => {
109
+ const token = await getAnonymousToken('application');
110
+ applicationToken.init = true;
111
+ applicationToken.accessToken = token.accessToken;
112
+ applicationToken.refreshToken = token.refreshToken;
113
+ const timestamps = new Date().getTime() + (token.expiresIn - 60) * 1000;
114
+ applicationToken.expiredAt = timestamps;
115
+ })();
116
+ return newTokenPromise;
109
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omerlo/omerlo-webkit",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",