Skip to content

Commit

Permalink
fix: added range validation for subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
vickywane committed Apr 15, 2021
1 parent 3f9fc99 commit b4effa7
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 33 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"idb": "^6.0.0",
"konva": "^7.1.4",
"moment": "^2.26.0",
"moment-range": "^4.0.2",
"node": "^15.4.0",
"peerjs": "^1.1.0",
"register-service-worker": "^1.7.1",
Expand Down
30 changes: 18 additions & 12 deletions src/components/authBarMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
v-if="!$auth.isAuthenticated"
style="display: flex;"
>
<!-- Cypress cant test Netlify forms as it's injected into the DOM. This manually sets the Auth state-->
<button
data-cy="auth-btn"
style="opacity: 0; color: white;"
Expand Down Expand Up @@ -176,6 +175,10 @@ import { mapState } from 'vuex'
import {
PEER_CONNECTED
} from '@/store/mutation-types'
import Moment from 'moment'
import { extendMoment } from 'moment-range'
const moment = extendMoment(Moment)
export default {
name: 'AuthBarMenu',
Expand All @@ -184,7 +187,8 @@ export default {
authMenu: false,
isAuthenticated: false,
showSubscription: false,
stripeId: null,
userSubscriptionId: null,
userStripeId: null,
isSubscribed: false,
showAuthenticationModal: false,
showEdgeSync: false
Expand All @@ -195,12 +199,9 @@ export default {
EdgeAuth0Sync: () => import('./edge-auth0-sync')
},
async created () {
console.log(this.$auth.user, 'AUTH0 DETAILS \n \n \n')
// waits for the auth0 client to be fully loaded
setTimeout(() => {
console.log(this.$auth)
if (this.$auth.user.sub) {
// alert(this.$auth.user.sub, 'sub')
this.fetchStripeId()
}
}, 1500)
Expand All @@ -211,10 +212,10 @@ export default {
this.showEdgeSync = true
},
cancelSubscription () {
Axios.delete(`${process.env.VUE_APP_FUNCTIONS_ENDPOINT}/subscription?stripeId=${this.stripeId}`,
Axios.delete(`${process.env.VUE_APP_FUNCTIONS_ENDPOINT}/subscription?stripeId=${this.userSubscriptionId}`,
{
data: {
stripeId: this.stripeId
stripeId: this.userSubscriptionId
},
headers: {
'content-type': 'application/json'
Expand All @@ -232,7 +233,8 @@ export default {
Axios.post(
`${process.env.VUE_APP_FUNCTIONS_ENDPOINT}/subscription-data`,
{
user_id: this.$auth.user.sub
user_id: this.$auth.user.sub,
userStripeId: this.userStripeId
},
{
headers: {
Expand All @@ -257,16 +259,20 @@ export default {
`${process.env.VUE_APP_FUNCTIONS_ENDPOINT}/subscription-data?userId=${this.$auth.user.sub}`
)
.then(({ data }) => {
const id = data.user.user_metadata.stripeId
const { userSubscriptionId, userStripeId, duration } = data.user.user_metadata
const today = Moment(new Date())
const subscriptionRange = moment.range(duration.start_date, duration.end_date)
const isActive = subscriptionRange.contains(today)
if (id) {
this.stripeId = id
if (isActive) {
this.userSubscriptionId = userSubscriptionId
this.userStripeId = userStripeId
this.isSubscribed = true
try {
const syncStatus = JSON.parse(localStorage.getItem('edgeSyncStatus'))
// alert(`${syncStatus.isSynced}, typeof: ${typeof syncStatus.isSynced}` )
if (!syncStatus.isSynced) {
this.showEdgeSync = true
}
Expand Down
48 changes: 30 additions & 18 deletions src/components/edge-auth0-sync.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@
<v-list-item>
<p>
Confirm the following code shown:
<span
<code
class="code"
id="verification_code"
>{{ user_code }}</span>
>{{ user_code }}</code>
, valid for 15 minutes.
</p>
</v-list-item>
</v-list>
<hr>
<br>
<div class="flex">
<p style="margin-right: 10px;">
{{ !isEdgeConnected ? "Connecting to edge device ..." : "Waiting for confirmation" }}
{{ !isEdgeConnected ? "Connecting to edge device ..." : "Waiting for your confirmation..." }}
</p>
<v-progress-circular
id="spinner"
Expand Down Expand Up @@ -140,7 +141,21 @@ export default {
this.edgeAPI = new EdgeAPI(this.pnp)
if (this.isEdgeConnected) {
console.log('HERE')
this.getUserCode()
}
},
methods: {
handleCompletion () {
this.showModal = false
localStorage.setItem('edgeSyncStatus', JSON.stringify({ isSynced: true }))
},
handleClose () {
localStorage.setItem('edgeSyncStatus', JSON.stringify({ isSynced: false }))
this.showModal = false
},
getUserCode () {
this.edgeAPI
.getUserCode()
.then((response) => {
Expand All @@ -155,18 +170,6 @@ export default {
.catch((e) => {
console.log('ERROR RESPONSE FROM EDGE', e)
})
}
},
methods: {
handleCompletion () {
this.showModal = false
localStorage.setItem('edgeSyncStatus', JSON.stringify({ isSynced: true }))
},
handleClose () {
localStorage.setItem('edgeSyncStatus', JSON.stringify({ isSynced: false }))
this.showModal = false
},
checkStatus () {
this.edgeAPI
Expand All @@ -180,8 +183,6 @@ export default {
this.checkStatus()
}, 4000)
} else if (response.access_token) {
console.log(response, 'RESPONSE \n \n \n \n \n')
this.edgeAPI
.saveUserToken({
email: this.$auth.user.email,
Expand All @@ -199,6 +200,13 @@ export default {
console.log(e, 'error from verify token')
})
}
},
watch: {
isEdgeConnected: function (value) {
if (value) {
this.getUserCode()
}
}
}
}
</script>
Expand All @@ -224,4 +232,8 @@ export default {
.icon:hover {
cursor: pointer;
}
.code {
font-weight: bold;
}
</style>
8 changes: 5 additions & 3 deletions src/components/subscriptionDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,20 @@ export default {
}
)
.then(({ data }) => {
this.saveStripeId(data.customerID)
const { userStripeId, userSubscriptionId } = data
this.saveStripeData(userStripeId, userSubscriptionId)
})
.catch((error) => {
console.log(error, 'ERROR FROM STRIPE')
this.showDialog = false
})
},
saveStripeId (id) {
saveStripeData (userStripeId, userSubscriptionId) {
Axios.post(
`${process.env.VUE_APP_FUNCTIONS_ENDPOINT}/subscription-data`,
{
stripeId: id,
userStripeId,
userSubscriptionId,
user_id: this.$auth.user.sub
},
{
Expand Down
63 changes: 63 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5286,6 +5286,14 @@ cypress@^6.9.1:
url "^0.11.0"
yauzl "^2.10.0"

d@1, d@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/d/-/d-1.0.1.tgz#8698095372d58dbee346ffd0c7093f99f8f9eb5a"
integrity sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==
dependencies:
es5-ext "^0.10.50"
type "^1.0.1"

dash-ast@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/dash-ast/-/dash-ast-1.0.0.tgz#12029ba5fb2f8aa6f0a861795b23c1b4b6c27d37"
Expand Down Expand Up @@ -5997,11 +6005,37 @@ es-to-primitive@^1.2.1:
is-date-object "^1.0.1"
is-symbol "^1.0.2"

es5-ext@^0.10.35, es5-ext@^0.10.50:
version "0.10.53"
resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.53.tgz#93c5a3acfdbef275220ad72644ad02ee18368de1"
integrity sha512-Xs2Stw6NiNHWypzRTY1MtaG/uJlwCk8kH81920ma8mvN8Xq1gsfhZvpkImLQArw8AHnv8MT2I45J3c0R8slE+Q==
dependencies:
es6-iterator "~2.0.3"
es6-symbol "~3.1.3"
next-tick "~1.0.0"

es6-error@^4.0.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.1.1.tgz#9e3af407459deed47e9a91f9b885a84eb05c561d"
integrity sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==

es6-iterator@~2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.3.tgz#a7de889141a05a94b0854403b2d0a0fbfa98f3b7"
integrity sha1-p96IkUGgWpSwhUQDstCg+/qY87c=
dependencies:
d "1"
es5-ext "^0.10.35"
es6-symbol "^3.1.1"

es6-symbol@^3.1.0, es6-symbol@^3.1.1, es6-symbol@~3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.3.tgz#bad5d3c1bcdac28269f4cb331e431c78ac705d18"
integrity sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==
dependencies:
d "^1.0.1"
ext "^1.1.2"

escalade@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40"
Expand Down Expand Up @@ -6491,6 +6525,13 @@ express@^4.16.3, express@^4.17.1:
utils-merge "1.0.1"
vary "~1.1.2"

ext@^1.1.2:
version "1.4.0"
resolved "https://registry.yarnpkg.com/ext/-/ext-1.4.0.tgz#89ae7a07158f79d35517882904324077e4379244"
integrity sha512-Key5NIsUxdqKg3vIsdw9dSuXpPCQ297y6wBjL30edxwPgt2E44WcWBZey/ZvUc6sERLTxKdyCu4gZFmUbk1Q7A==
dependencies:
type "^2.0.0"

extend-shallow@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f"
Expand Down Expand Up @@ -10501,6 +10542,13 @@ module-deps@^6.0.0, module-deps@^6.2.3:
through2 "^2.0.0"
xtend "^4.0.0"

moment-range@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/moment-range/-/moment-range-4.0.2.tgz#f7c3863df2a1ed7fd1822ba5a7bcf53a78701be9"
integrity sha512-n8sceWwSTjmz++nFHzeNEUsYtDqjgXgcOBzsHi+BoXQU2FW+eU92LUaK8gqOiSu5PG57Q9sYj1Fz4LRDj4FtKA==
dependencies:
es6-symbol "^3.1.0"

moment@^2.26.0, moment@^2.29.1:
version "2.29.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
Expand Down Expand Up @@ -10607,6 +10655,11 @@ nerf-dart@^1.0.0:
resolved "https://registry.yarnpkg.com/nerf-dart/-/nerf-dart-1.0.0.tgz#e6dab7febf5ad816ea81cf5c629c5a0ebde72c1a"
integrity sha1-5tq3/r9a2Bbqgc9cYpxaDr3nLBo=

next-tick@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c"
integrity sha1-yobR/ogoFpsBICCOPchCS524NCw=

nice-try@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
Expand Down Expand Up @@ -14492,6 +14545,16 @@ type-is@~1.6.17, type-is@~1.6.18:
media-typer "0.3.0"
mime-types "~2.1.24"

type@^1.0.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/type/-/type-1.2.0.tgz#848dd7698dafa3e54a6c479e759c4bc3f18847a0"
integrity sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==

type@^2.0.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/type/-/type-2.5.0.tgz#0a2e78c2e77907b252abe5f298c1b01c63f0db3d"
integrity sha512-180WMDQaIMm3+7hGXWf12GtdniDEy7nYcyFMKJn/eZz/6tSLXrUN9V0wKSbMjej0I1WHWbpREDEKHtqPQa9NNw==

typedarray-to-buffer@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080"
Expand Down

0 comments on commit b4effa7

Please sign in to comment.