Skip to content

Commit

Permalink
feat: pull refresh token from hypha auth service
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-IS committed Nov 27, 2023
1 parent 10d56d3 commit c700feb
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 42 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/deploy-eos-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: EOS - Build and Deploy to Staging - MainNet

on:
push:
branches: [ master ]
branches:
- master
- feat/add-support-for-dgraph-cloud-with-namespaces

jobs:
build:
Expand All @@ -21,7 +23,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '16.x'
node-version: '18.x'
- run: yarn global add @vue/cli@latest
- run: yarn install
- run: mv public/chain-manifests-prod.json public/chain-manifests.json
Expand All @@ -36,6 +38,8 @@ jobs:
MULTISIG_CONTRACT: 'msig.hypha'
KV_CONTRACT: 'kv.hypha'
PPP_ENV: ${{ vars.PPP_ENV }}
ENV: 'prod'
HYPHA_AUTH_URL: ${{ vars.HYPHA_AUTH_URL }}
PPP_APP_ID: ${{ vars.PPP_APP_ID }}
ACCOUNT_API_URL: ${{ vars.ACCOUNT_API_URL }}
ACCOUNT_API_KEY: ${{ secrets.ACCOUNT_API_KEY }}
Expand All @@ -44,14 +48,14 @@ jobs:
BLOCKCHAIN_EXPLORER_BTC: 'https://www.blockchain.com/btc/tx/'
BLOCKCHAIN_EXPLORER_ETH: 'https://etherscan.io/tx/'
BLOCKCHAIN_EXPLORER_EOS: 'https://bloks.io/transaction/'

CHAIN_NAME: 'eos'
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
DOCUMENTATION: ${{ vars.DOCUMENTATION }}

DGRAPH_URL: ${{ vars.DGRAPH_URL }}
DGRAPH_URL: https://hypha.us-east-1.aws.cloud.dgraph.io
DGRAPH_ROOT_HASH: ${{ vars.DGRAPH_ROOT_HASH }}
DGRAPH_AUTH_KEY: ${{ secrets.DGRAPH_AUTH_KEY }}
GRAPHQL_URI: ${{vars.GRAPHQL_URI}}
GRAPHQL_URI: https://hypha.us-east-1.aws.cloud.dgraph.io/graphql
ROOT_DAO_ID: ${{vars.ROOT_DAO_ID}}
ROOT_DAO_SLUG: ${{vars.ROOT_DAO_SLUG}}
HEALTH_ENDPOINT: ${{ vars.HEALTH_ENDPOINT }}
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"author": "Max <[email protected]>",
"license": "Apache-2.0",
"scripts": {
"dev": "export NODE_OPTIONS=--openssl-legacy-provider && quasar dev -m spa",
"dev": "quasar dev -m spa",
"dev:eos": "env-cmd -f ./config/eos-testnet.env quasar dev -m spa",
"prod:telos": "env-cmd -f ./config/telos-mainnet.env quasar dev -m spa",
"prod:eos": "env-cmd -f ./config/eos-mainnet.env quasar dev -m spa",
"build": "quasar build",
"build": "NODE_OPTIONS=--openssl-legacy-provider quasar build",
"lint": "eslint --ext .js,.vue .",
"test": "exit 0",
"storybook": "start-storybook -s ./public -p 6006",
Expand All @@ -32,6 +32,7 @@
"@sentry/integrations": "6.3.1",
"@sentry/tracing": "^7.14.2",
"@sentry/vue": "^7.14.2",
"apollo-link-token-refresh": "v0.2",
"apollo-link-ws": "^1.0.20",
"apollo-utilities": "^1.3.4",
"axios": "0.21.1",
Expand All @@ -44,6 +45,7 @@
"eosjs-ecc": "^4.0.7",
"ipfs-http-client": "55.0.0",
"it-all": "^1.0.6",
"jwt-decode": "^4.0.0",
"libphonenumber-js": "^1.10.6",
"qrcode.vue": "1.7.0",
"quasar": "1.15.10",
Expand Down
17 changes: 13 additions & 4 deletions quasar.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,25 @@ module.exports = function (ctx) {
HYPHA_TOKEN_SALES_RPC_URL: process.env.HYPHA_TOKEN_SALES_RPC_URL,
PACKAGE_VERSION: JSON.parse(packageJson).version || 0,
HEALTH_ENDPOINT: process.env.HEALTH_ENDPOINT,
CHAIN_NAME: process.env.CHAIN_NAME,
CHAIN_NAME: process.env.CHAIN_NAME || 'telos',
IS_TESTNET: process.env.IS_TESTNET,
HYPHA_AUTH_URL:
process.env.HYPHA_AUTH_URL ||
'https://y3b2ihsdv7.execute-api.us-east-1.amazonaws.com',
CAPTCHA_PUBLIC_KEY: process.env.CAPTCHA_PUBLIC_KEY,
CAPTCHA_HOST: process.env.CAPTCHA_HOST,
CAPTCHA_NETWORK: process.env.CAPTCHA_NETWORK || 'telosTestnet',
LOGIN_CONTRACT: process.env.LOGIN_CONTRACT,
JOIN_CONTRACT: process.env.JOIN_CONTRACT,
JOIN_URI: process.env.JOIN_URI,
DEFFERED_HYPHA_CONTRACT: process.env.DEFFERED_HYPHA_CONTRACT || 'costak.hypha',
DOWNLOAD_WALLET_LINK_IOS: process.env.DOWNLOAD_WALLET_LINK_IOS || "http://itunes.apple.com/lb/app/1659926348",
DOWNLOAD_WALLET_LINK_ANDROID: process.env.DOWNLOAD_WALLET_LINK_ANDROID || "http://play.google.com/store/apps/details?id=earth.hypha.wallet.hypha_wallet"
DEFFERED_HYPHA_CONTRACT:
process.env.DEFFERED_HYPHA_CONTRACT || 'costak.hypha',
DOWNLOAD_WALLET_LINK_IOS:
process.env.DOWNLOAD_WALLET_LINK_IOS ||
'http://itunes.apple.com/lb/app/1659926348',
DOWNLOAD_WALLET_LINK_ANDROID:
process.env.DOWNLOAD_WALLET_LINK_ANDROID ||
'http://play.google.com/store/apps/details?id=earth.hypha.wallet.hypha_wallet'
},

scopeHoisting: true,
Expand Down
7 changes: 5 additions & 2 deletions src/apollo/apollo-client-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { IntrospectionFragmentMatcher, defaultDataIdFromObject } from 'apollo-cache-inmemory'
import {
IntrospectionFragmentMatcher,
defaultDataIdFromObject
} from 'apollo-cache-inmemory'
import schema from './schema.json'

export default async function (/* { app, router, store, ssrContext, urlPath, redirect } */) {
Expand All @@ -20,7 +23,7 @@ export default async function (/* { app, router, store, ssrContext, urlPath, red
fragmentMatcher: new IntrospectionFragmentMatcher({
introspectionQueryResultData: schema
}),
dataIdFromObject: r => {
dataIdFromObject: (r) => {
if (r.docId && r.__typename) {
return `${r.__typename}:${r.docId}`
}
Expand Down
81 changes: 74 additions & 7 deletions src/apollo/apollo-client-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,67 @@ import { HttpLink } from 'apollo-link-http'
import { split } from 'apollo-link'
import { WebSocketLink } from 'apollo-link-ws'
import { getMainDefinition } from 'apollo-utilities'
import { TokenRefreshLink } from 'apollo-link-token-refresh' // import TokenRefreshLink
import { jwtDecode } from 'jwt-decode'

const hyphaAccessTokenKey = 'hyphaAccessToken'
const hyphaRefreshTokenKey = 'hyphaRefreshToken'

const tokenRefreshLink = new TokenRefreshLink({
isTokenValidOrUndefined: () => {
const token = localStorage.getItem(hyphaAccessTokenKey)
if (!token) return false // if no token, assume it's valid

try {
const { exp } = jwtDecode(token)

return Date.now() < exp * 1000
} catch {
return false
}
},
fetchAccessToken: () => {
const HYPHA_AUTH_URL = process.env.HYPHA_AUTH_URL
const CHAIN_NAME = process.env.CHAIN_NAME
const ENV = process.env.ENV || process.env.PPP_ENV || 'prod'
const network = process.env.IS_TESTNET ? 'testnet' : 'mainnet'
const url = `${HYPHA_AUTH_URL}?chain=${CHAIN_NAME}&env=${ENV}&network=${network}`

return fetch(url, {
method: 'GET'
})
},
handleFetch: (accessToken) => {
localStorage.setItem(hyphaAccessTokenKey, accessToken)
},
handleResponse: (operation, accessTokenField) => async (response) => {
const data = await response.json()

localStorage.setItem(hyphaAccessTokenKey, data.accessJWT)
localStorage.setItem(hyphaRefreshTokenKey, data.refreshJWT)

return response
},
handleError: (err) => {

Check failure on line 46 in src/apollo/apollo-client-hooks.js

View workflow job for this annotation

GitHub Actions / build-eos-mainnet-staging

Expected error to be handled
// Handle token refresh errors (e.g., logout user)
localStorage.removeItem(hyphaRefreshTokenKey)
}
})

const httpLink = new HttpLink({
// You should use an absolute URL here
uri: process.env.GRAPHQL_URI || 'https://alpha-stt.tekit.io/graphql'
uri: process.env.GRAPHQL_URI || 'https://alpha-stt.tekit.io/graphql',
fetch: (uri, options) => {
const accessToken = localStorage.getItem(hyphaAccessTokenKey) // get the access token from storage
options.headers['X-Dgraph-AccessToken'] = accessToken
return fetch(uri, options)
}
})

// Create the subscription websocket link
const wsLink = new WebSocketLink({
uri: process.env.GRAPHQL_URI.replace('https', 'wss') || 'wss://alpha-stts.tekit.io/graphql',
uri:
process.env.GRAPHQL_URI.replace('https', 'wss') ||
'wss://alpha-stts.tekit.io/graphql',
options: {
reconnect: true
}
Expand All @@ -22,20 +74,35 @@ const link = split(
// split based on operation type
({ query }) => {
const definition = getMainDefinition(query)
return definition.kind === 'OperationDefinition' &&
return (
definition.kind === 'OperationDefinition' &&
definition.operation === 'subscription'
)
},
wsLink,
httpLink
tokenRefreshLink.concat(httpLink)
)

export async function apolloClientBeforeCreate ({ apolloClientConfigObj, app, router, store, ssrContext, urlPath, redirect }) {
export async function apolloClientBeforeCreate({
apolloClientConfigObj,
app,
router,
store,
ssrContext,
urlPath,
redirect
}) {
// if needed you can modify here the config object used for apollo client
// instantiation
apolloClientConfigObj.link = link
}

export async function apolloClientAfterCreate ({ apolloClient, store }/* { apolloClient, app, router, store, ssrContext, urlPath, redirect } */) {
export async function apolloClientAfterCreate(
{
apolloClient,
store
} /* { apolloClient, app, router, store, ssrContext, urlPath, redirect } */
) {
// if needed you can modify here the created apollo client
store.$apollo = apolloClient
}
2 changes: 1 addition & 1 deletion src/components/navigation/left-navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
}
},
fetchPolicy: 'no-cache',
pollInterval: 1000,
// pollInterval: 1000,
skip () { return !this.selectedDao || !this.selectedDao.docId }
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/profiles/wallet-base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export default {
username: this.account
}
},
skip () { return !this.selectedDao?.docId },
pollInterval: 1000
// pollInterval: 1000,
skip () { return !this.selectedDao?.docId }
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/proposals/voter-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ export default {
query: gql`query proposalVotes($docId: String!, $first: Int!, $offset: Int!) { ${PROPOSAL_VOTES_QUERY} }`,
update: data => data.queryVote,
skip () { return !this.proposalId },
// pollInterval: 1000,
variables () {
return {
docId: this.proposalId,
first: this.size,
offset: this.page * this.size
}
},
}
// fetchPolicy: 'no-cache',
pollInterval: 1000
// subscribeToMore: {
// document: gql`subscription proposalVotes($docId: String!, $first: Int, $offset: Int) { ${PROPOSAL_VOTES_QUERY} }`,
// skip () { return !this.proposalId },
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dho/Ecosystem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export default {
})
},
variables () { return { daoId: this.selectedDao.docId } },
skip () { return !this.selectedDao?.docId },
pollInterval: 1000 // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
// pollInterval: 1000 // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
skip () { return !this.selectedDao?.docId }
}
},
Expand Down
6 changes: 3 additions & 3 deletions src/pages/dho/Election.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default {
}
},
fetchPolicy: 'no-cache',
pollInterval: 1000, // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
// pollInterval: 1000, // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
skip () { return !this.selectedDao || !this.selectedDao.docId }
},
ongoingElection: {
Expand All @@ -94,7 +94,7 @@ export default {
}
},
fetchPolicy: 'no-cache',
pollInterval: 1000, // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
// pollInterval: 1000, // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
skip () { return !this.selectedDao || !this.selectedDao.docId }
},
upcomingElection: {
Expand All @@ -106,7 +106,7 @@ export default {
}
},
fetchPolicy: 'no-cache',
pollInterval: 1000, // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
// pollInterval: 1000, // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
skip () { return !this.selectedDao || !this.selectedDao.docId }
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dho/Explore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default {
daoName: '',
first: 6,
offset: 0,
more: true,
more: false,
restart: false,
view: 'card',
Expand Down Expand Up @@ -200,7 +200,7 @@ export default {
async resetPagination () {
this.restart = true
this.offset = 0
this.more = true
this.more = false
await this.$nextTick()
this.$refs.scroll.stop()
Expand Down
12 changes: 6 additions & 6 deletions src/pages/dho/Treasury.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export default {
skip () {
return !this.selectedDao || !this.selectedDao.docId
},
// pollInterval: 1000 // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
variables () {
const rowsPerPage = this.pagination.rowsPerPage || 10
return {
Expand All @@ -181,8 +182,7 @@ export default {
},
filter: this.tab === MULTISIG_TABS.PAYOUT ? { not: { has: 'paidby' } } : {}
}
},
pollInterval: 1000 // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
}
},
daoMultisigSignRequestsQuery: {
query: require('~/query/treasury/dao-multisig-sign-requests.gql'),
Expand All @@ -208,8 +208,8 @@ export default {
daoId: this.selectedDao.docId
}
},
skip () { return !this.selectedDao?.docId },
pollInterval: 1000 // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
// pollInterval: 1000 // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
skip () { return !this.selectedDao?.docId }
},
daoMultisigReadyExecRequestsQuery: {
query: require('~/query/treasury/dao-multisig-sign-requests.gql'),
Expand Down Expand Up @@ -237,10 +237,10 @@ export default {
}
},
skip () { return !this.selectedDao?.docId },
// pollInterval: 1000 // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
result: async function () {
await this.formatExecReuqests()
},
pollInterval: 1000 // THIS IS JUST TEMPORARY UNTIL GRAPHQL SUBSCRIPTION IS READY
}
}
},
async beforeMount () {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/onboarding/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ export default {
const query = await this.$apollo.watchQuery({
query: isDraft ? require('~/query/dao-draft-created.gql') : require('~/query/dao-created.gql'),
// pollInterval: 100,
variables: isDraft ? { daoName: this.form.name } : { regexp: '/^' + this.form.name + '$/i' },
pollInterval: 100
})
query.subscribe(({ data, loading }) => {
Expand Down
Loading

0 comments on commit c700feb

Please sign in to comment.