Skip to content
This repository was archived by the owner on Nov 21, 2022. It is now read-only.

Commit e451187

Browse files
authored
enh/enhance cognito isLoggedIn getter (#9)
* refactor(cognito): enhances isLoggedIn getter to also check username/expiration * style(cognito): add whitespace for readability
1 parent e0b229c commit e451187

File tree

4 files changed

+37
-35
lines changed

4 files changed

+37
-35
lines changed

packages/cognito-module/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"url": "https://github.com/vuetifyjs/vuex/tree/master/packages/cognito-module"
1616
},
1717
"dependencies": {
18-
"@aws-amplify/auth": "^1.2.4",
19-
"@aws-amplify/core": "^1.0.13"
18+
"@aws-amplify/auth": "^1.2.18",
19+
"@aws-amplify/core": "^1.0.23"
2020
},
2121
"devDependencies": {
2222
"@vue/babel-preset-app": "^3.0.4",
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
module.exports = {
22
// TODO: ensure best method to verify this
33
isLoggedIn: (store = {}) => {
4-
return Boolean(
5-
store.session &&
6-
store.session.accessToken &&
7-
store.session.accessToken.jwtToken
8-
)
4+
const session = store.session
5+
if (!session) return false
6+
const accessToken = session.accessToken
7+
if (!accessToken) return false
8+
const hasToken = accessToken.jwtToken
9+
const isActive = new Date(accessToken.payload.exp * 1000) > new Date()
10+
const isMe = accessToken.payload.username === store.user.username
11+
12+
return hasToken && isActive && isMe
913
}
1014
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
// Utils
2-
31
export default {
42
setUser: (state, user) => {
5-
state.user = JSON.parse(JSON.stringify(user))
3+
state.user = { ...user }
64
state.session = state.user.signInUserSession
75
}
86
}

yarn.lock

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
# yarn lockfile v1
33

44

5-
"@aws-amplify/auth@^1.2.4":
6-
version "1.2.10"
7-
resolved "https://registry.yarnpkg.com/@aws-amplify/auth/-/auth-1.2.10.tgz#db55f848e801dc44a6f246d2963135f639431ce9"
8-
integrity sha512-IjNKszriGrAtCHR2ZQJZ4I84WgCVdDQHNvDjzUGhXPg2q1eu1l6mp5xgVgxbeedooNcKIMI9Qj6cUKxC+9kJfw==
5+
"@aws-amplify/auth@^1.2.18":
6+
version "1.2.18"
7+
resolved "https://registry.yarnpkg.com/@aws-amplify/auth/-/auth-1.2.18.tgz#617b11b777483a6c60ef4f9fd67b2b62fafaca13"
8+
integrity sha512-8fNzSP99Vfh+ZcWWvaBmL5TfB8tXNIvYH36VuH+3hqSICouZ64+aN5aaDAP+jWgk0km1Kqau7DzEVjh6qCfn2Q==
99
dependencies:
10-
"@aws-amplify/cache" "^1.0.18"
11-
"@aws-amplify/core" "^1.0.18"
12-
amazon-cognito-auth-js "^1.1.9"
13-
amazon-cognito-identity-js "^3.0.3"
10+
"@aws-amplify/cache" "^1.0.23"
11+
"@aws-amplify/core" "^1.0.23"
12+
amazon-cognito-auth-js "^1.3.2"
13+
amazon-cognito-identity-js "^3.0.9"
1414

15-
"@aws-amplify/cache@^1.0.18":
16-
version "1.0.18"
17-
resolved "https://registry.yarnpkg.com/@aws-amplify/cache/-/cache-1.0.18.tgz#a25c28d7eb2f55f237a9fc6a68fae771b565fb45"
18-
integrity sha512-3VqnmQeDo2JwvLUMEYrj4s/Yi8UEF4Ej6UyKMg9htktyrQf0pYriniy/vjGaBVZGajh2HnrIgYSDQPkUXPW4bQ==
15+
"@aws-amplify/cache@^1.0.23":
16+
version "1.0.23"
17+
resolved "https://registry.yarnpkg.com/@aws-amplify/cache/-/cache-1.0.23.tgz#a15a2e030cd0e22998a4f294143dcf695667241e"
18+
integrity sha512-qH120o8A+nwJHs/Cih/HW7fqXto6bShF3hYDxCph7UvuQqBAeNCzu/dmLIO0gxWZnATf8Pjg15u4D1clYQMpaQ==
1919
dependencies:
20-
"@aws-amplify/core" "^1.0.18"
20+
"@aws-amplify/core" "^1.0.23"
2121

22-
"@aws-amplify/core@^1.0.13", "@aws-amplify/core@^1.0.18":
23-
version "1.0.18"
24-
resolved "https://registry.yarnpkg.com/@aws-amplify/core/-/core-1.0.18.tgz#24377c5d18a2316628022b7c32c0631ded47b8bc"
25-
integrity sha512-a+9/vhK/YF2Hu4umwlgol+rGpsW8FyBsrKFwDSkHmfk9RFVE0F4sNgiQTJ7BkhURigi+3BrPNUiTspN05Thc+A==
22+
"@aws-amplify/core@^1.0.23":
23+
version "1.0.23"
24+
resolved "https://registry.yarnpkg.com/@aws-amplify/core/-/core-1.0.23.tgz#d9ac79ead544a0ca2a221a2d5ab20e22995b2a49"
25+
integrity sha512-zJJcgoYwncJfrbigBbQLU5qF+g6PM3eyM45XwyiwHKixTFHUpQTgq+rCy2wfLodyEjrmggrisR9+wBdVOZvVTg==
2626
dependencies:
2727
aws-sdk "2.329.0"
2828
url "^0.11.0"
@@ -2495,17 +2495,17 @@ alphanum-sort@^1.0.0, alphanum-sort@^1.0.1, alphanum-sort@^1.0.2:
24952495
resolved "https://registry.yarnpkg.com/alphanum-sort/-/alphanum-sort-1.0.2.tgz#97a1119649b211ad33691d9f9f486a8ec9fbe0a3"
24962496
integrity sha1-l6ERlkmyEa0zaR2fn0hqjsn74KM=
24972497

2498-
amazon-cognito-auth-js@^1.1.9:
2499-
version "1.2.4"
2500-
resolved "https://registry.yarnpkg.com/amazon-cognito-auth-js/-/amazon-cognito-auth-js-1.2.4.tgz#40d82f0ed389905fd0751693ba46a5386ac6864a"
2501-
integrity sha512-Walq6lIHB+MBOEfg0RBezURTDBKvUO4H9xpW2DBLZT3aDTF+p8awKHe2AujdHYItkefOhdjwu4GqjFgo4RkG+A==
2498+
amazon-cognito-auth-js@^1.3.2:
2499+
version "1.3.2"
2500+
resolved "https://registry.yarnpkg.com/amazon-cognito-auth-js/-/amazon-cognito-auth-js-1.3.2.tgz#975aa6f2f6d5e39d364ff27a39b971d3d7d4b9fb"
2501+
integrity sha512-XeCZN1QVGXN61PTTkgUrTm89/ukLQAZbOkJXFm9FSCtq1lVMmCKgxAuslMYh+IHmvJifIVypfvb6uiQl5EHCPg==
25022502
dependencies:
25032503
js-cookie "^2.1.4"
25042504

2505-
amazon-cognito-identity-js@^3.0.3:
2506-
version "3.0.3"
2507-
resolved "https://registry.yarnpkg.com/amazon-cognito-identity-js/-/amazon-cognito-identity-js-3.0.3.tgz#4095ee649648c10d725517ed82e7b53f19644814"
2508-
integrity sha512-zRhhJrei4qj5k7obD2B3aCEk06mVoa1yZQk4P+pjHkUfsHSAqewpJ/IhymDYeQjB396evvKIGjxKPjLVguRYRw==
2505+
amazon-cognito-identity-js@^3.0.9:
2506+
version "3.0.9"
2507+
resolved "https://registry.yarnpkg.com/amazon-cognito-identity-js/-/amazon-cognito-identity-js-3.0.9.tgz#7a064e0dcc68a4739a47e68af792e7dbfeb67bc3"
2508+
integrity sha512-RhgFLF81jmjjNIn8EbofPKeyarQ3aiGwBts1LtZDsmE8bHsRSom15xA23XTAfPBpboW+XZyFYbNc6vnOHnIAwg==
25092509
dependencies:
25102510
buffer "4.9.1"
25112511
crypto-js "^3.1.9-1"

0 commit comments

Comments
 (0)