-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create a custom store for premium functionality
- Loading branch information
1 parent
f2fa4d1
commit 2d919d2
Showing
4 changed files
with
130 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
export const state = () => ({ | ||
gumroad: { | ||
authAPI: { | ||
url: 'https://auth.r34.app/', | ||
|
||
fetchOptions: { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: undefined, // Must be set by a getter | ||
}, | ||
}, | ||
|
||
product: { | ||
product_permalink: 'gRuqQm', | ||
license_key: undefined, | ||
}, | ||
}, | ||
|
||
responseData: undefined, | ||
}) | ||
|
||
export const getters = { | ||
isUserPremium(state, getters, rootState) { | ||
return ( | ||
state.responseData && | ||
state.responseData.success === true && | ||
state.responseData.purchase.disputed === false && | ||
state.responseData.purchase.refunded === false && | ||
state.responseData.purchase.subscription_cancelled_at === null && | ||
state.responseData.purchase.subscription_failed_at === null | ||
) | ||
}, | ||
|
||
getUserEmail(state) { | ||
return state.responseData && state.responseData.success | ||
? state.responseData.purchase.email | ||
: undefined | ||
}, | ||
|
||
getFetchOptionsInit(state) { | ||
return { | ||
...state.gumroad.authAPI.fetchOptions, | ||
|
||
body: JSON.stringify(state.gumroad.product), | ||
} | ||
}, | ||
} | ||
|
||
export const mutations = { | ||
setRawResponse(state, response) { | ||
state.responseData = response | ||
}, | ||
|
||
removeRawResponse(state) { | ||
state.responseData = undefined | ||
}, | ||
|
||
setLicenseKey(state, licenseKey) { | ||
state.gumroad.product.license_key = licenseKey | ||
}, | ||
|
||
removeLicenseKey(state) { | ||
state.gumroad.product.license_key = undefined | ||
}, | ||
} | ||
|
||
export const actions = { | ||
async authenticate({ state, dispatch, commit, getters }) { | ||
const response = await dispatch( | ||
'simpleFetch', | ||
{ | ||
url: state.gumroad.authAPI.url, | ||
options: getters.getFetchOptionsInit, | ||
}, | ||
{ root: true } // Necessary for tlaking to root actions | ||
) | ||
|
||
// console.log(response) | ||
commit('setRawResponse', response) | ||
}, | ||
} |