propro-utils 1.4.48 → 1.4.50

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.4.48",
3
+ "version": "1.4.50",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -56,7 +56,6 @@ function proproAuthMiddleware(options = {}, userSchema) {
56
56
  if (req.cookies) {
57
57
  refreshToken = req.cookies['x-refresh-token'];
58
58
  }
59
- console.log('refreshing tokens: ', refreshToken);
60
59
  if (!refreshToken) {
61
60
  const redirectUrl = constructRedirectUrl(
62
61
  clientUrl,
@@ -121,13 +120,9 @@ function proproAuthMiddleware(options = {}, userSchema) {
121
120
  );
122
121
 
123
122
  const user = await checkIfUserExists(userSchema, account.accountId);
124
- console.log('user: ', user);
125
123
 
126
- console.log('setting cookies: ', tokens, account, user);
127
124
  setAuthCookies(res, tokens, account, user);
128
125
 
129
- console.log('setting cookies and redirectUrl: ', redirectUrl);
130
-
131
126
  const urlToRedirect = formatRedirectUrl(redirectUrl);
132
127
 
133
128
  return res.redirect(urlToRedirect);
@@ -39,7 +39,7 @@ const setAuthCookies = (res, tokens, account, user) => {
39
39
 
40
40
  res.cookie(
41
41
  'has_account_token',
42
- JSON.stringify({ value: 'true', expires: expirationTime }),
42
+ JSON.stringify({ value: 'true', expires: accessMaxAge }),
43
43
  {
44
44
  maxAge: accessMaxAge,
45
45
  secure: process.env.NODE_ENV === 'production',
@@ -76,14 +76,6 @@ describe('setAuthCookies', () => {
76
76
  );
77
77
  });
78
78
 
79
- it('should set the has_account_token cookie with the correct options', () => {
80
- setAuthCookies(res, tokens, account, user);
81
- expect(res.cookie).toHaveBeenCalledWith('has_account_token', 'true', {
82
- maxAge: expect.any(Number),
83
- secure: process.env.NODE_ENV === 'production',
84
- });
85
- });
86
-
87
79
  it('should set the maxAge of refresh-related cookies to the correct value', () => {
88
80
  const currentDateTime = new Date();
89
81
  const refreshMaxAge =
@@ -116,10 +108,22 @@ describe('setAuthCookies', () => {
116
108
  expect.any(String),
117
109
  expect.objectContaining({ maxAge: accessMaxAge })
118
110
  );
111
+ });
112
+
113
+ it('should set the has_account_token cookie with the correct options', () => {
114
+ const currentDateTime = new Date();
115
+ const accessMaxAge =
116
+ new Date(tokens.access.expires).getTime() - currentDateTime.getTime();
117
+
118
+ setAuthCookies(res, tokens, account, user);
119
+
119
120
  expect(res.cookie).toHaveBeenCalledWith(
120
121
  'has_account_token',
121
- expect.any(String),
122
- expect.objectContaining({ maxAge: accessMaxAge })
122
+ JSON.stringify({ value: 'true', expires: accessMaxAge }),
123
+ {
124
+ maxAge: accessMaxAge,
125
+ secure: process.env.NODE_ENV === 'production',
126
+ }
123
127
  );
124
128
  });
125
129
  });