Skip to content

Commit

Permalink
Fix token expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
AymericBethencourt committed Feb 9, 2021
1 parent 01ea556 commit 5a0de27
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 28 deletions.
9 changes: 9 additions & 0 deletions src/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:alpine
RUN mkdir -p /app
WORKDIR /app
COPY . /app
RUN cd /app
RUN yarn install
RUN yarn build
EXPOSE 3000
CMD ["node", "dist/index.js"]
15 changes: 2 additions & 13 deletions src/api/kubernetesDeployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,8 @@
"containers": [
{
"name": "tezosacademy-api",
"image": "registry.digitalocean.com/octo/tezosacademy-api",
"imagePullPolicy": "Always",
"env": [
{
"name": "TEST_KEY",
"valueFrom": {
"secretKeyRef": {
"name": "person",
"key": "TEST_KEY"
}
}
}
]
"image": "registry.digitalocean.com/rtx/tezosacademy-api",
"imagePullPolicy": "Always"
}
]
}
Expand Down
8 changes: 4 additions & 4 deletions src/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"build": "PORT=3000 NODE_ENV=production tsc",
"analyze": "PORT=3000 NODE_ENV=production tsc && npx source-map-explorer 'build/static/js/*.js'",
"docker-create": "doctl k8s cluster create --region fra1 --node-pool \"name=tezosacademy-api;size=s-1vcpu-2gb;count=1;auto-scale=true;min-nodes=1;max-nodes=3\" tezosacademy-api --wait && doctl kubernetes cluster kubeconfig save tezosacademy-api",
"docker-build": "docker build -t octo/tezosacademy-api . --no-cache",
"docker-run": "docker run --rm -it -p 3000:3000 octo/tezosacademy-api",
"docker-push": "doctl registry login && docker tag octo/tezosacademy-api registry.digitalocean.com/octo/tezosacademy-api && docker push registry.digitalocean.com/octo/tezosacademy-api",
"docker-patch": "doctl registry kubernetes-manifest | kubectl --context do-fra1-tezosacademy-api apply -f - && kubectl --context do-fra1-tezosacademy-api patch serviceaccount default -p '{\"imagePullSecrets\": [{\"name\": \"registry-octo\"}]}'",
"docker-build": "docker build -t rtx/tezosacademy-api . --no-cache",
"docker-run": "docker run --rm -it -p 3000:3000 rtx/tezosacademy-api",
"docker-push": "doctl registry login && docker tag rtx/tezosacademy-api registry.digitalocean.com/rtx/tezosacademy-api && docker push registry.digitalocean.com/rtx/tezosacademy-api",
"docker-patch": "doctl registry kubernetes-manifest | kubectl --context do-fra1-tezosacademy-api apply -f - && kubectl --context do-fra1-tezosacademy-api patch serviceaccount default -p '{\"imagePullSecrets\": [{\"name\": \"registry-rtx\"}]}'",
"docker-secrets": "kubectl --context do-fra1-tezosacademy-api create secret generic person --from-env-file=.testenv",
"docker-deploy": "kubectl --context do-fra1-tezosacademy-api apply -f kubernetesDeployment.json",
"docker-serve": "kubectl --context do-fra1-tezosacademy-api apply -f kubernetesService.json",
Expand Down
2 changes: 1 addition & 1 deletion src/api/src/kubernetes.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"containers": [
{
"name": "tezosacademy-api",
"image": "registry.digitalocean.com/octo/tezosacademy-api",
"image": "registry.digitalocean.com/rtx/tezosacademy-api",
"imagePullPolicy": "Always"
}
],
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/kubernetesDeployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"containers": [
{
"name": "tezosacademy-frontend",
"image": "registry.digitalocean.com/octo/tezosacademy-frontend",
"image": "registry.digitalocean.com/rtx/tezosacademy-frontend",
"imagePullPolicy": "Always"
}
]
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"start": "PORT=3000 NODE_ENV=development REACT_APP_BACKEND_URL=http://localhost:8080 react-scripts -r @cypress/instrument-cra start && open http://localhost:3000",
"build": "INLINE_RUNTIME_CHUNK=false react-scripts build && cra-append-sw -s ./src/custom-sw.js",
"docker-create": "doctl k8s cluster create --region fra1 --node-pool \"name=tezosacademy-frontend;size=s-1vcpu-2gb;count=1;auto-scale=true;min-nodes=1;max-nodes=3\" tezosacademy-frontend --wait && doctl kubernetes cluster kubeconfig save tezosacademy-frontend",
"docker-build": "yarn build && docker build -t octo/tezosacademy-frontend . --no-cache",
"docker-run": "docker run --rm -it -p 80:80 octo/tezosacademy-frontend",
"docker-push": "doctl registry login && docker tag octo/tezosacademy-frontend registry.digitalocean.com/octo/tezosacademy-frontend && docker push registry.digitalocean.com/octo/tezosacademy-frontend",
"docker-patch": "doctl registry kubernetes-manifest | kubectl --context do-fra1-tezosacademy-frontend apply -f - && kubectl --context do-fra1-tezosacademy-frontend patch serviceaccount default -p '{\"imagePullSecrets\": [{\"name\": \"registry-octo\"}]}'",
"docker-build": "yarn build && docker build -t rtx/tezosacademy-frontend . --no-cache",
"docker-run": "docker run --rm -it -p 80:80 rtx/tezosacademy-frontend",
"docker-push": "doctl registry login && docker tag rtx/tezosacademy-frontend registry.digitalocean.com/rtx/tezosacademy-frontend && docker push registry.digitalocean.com/rtx/tezosacademy-frontend",
"docker-patch": "doctl registry kubernetes-manifest | kubectl --context do-fra1-tezosacademy-frontend apply -f - && kubectl --context do-fra1-tezosacademy-frontend patch serviceaccount default -p '{\"imagePullSecrets\": [{\"name\": \"registry-rtx\"}]}'",
"docker-secrets": "kubectl --context do-fra1-tezosacademy-frontend create secret generic person --from-env-file=.env",
"docker-deploy": "kubectl --context do-fra1-tezosacademy-frontend apply -f kubernetesDeployment.json",
"docker-serve": "kubectl --context do-fra1-tezosacademy-frontend apply -f kubernetesService.json",
Expand Down
23 changes: 18 additions & 5 deletions src/frontend/src/app/App.offline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react'
import * as ReactDOM from 'react-dom'

import { Root, store } from '../index'
import { restore } from './App.actions'
import { redirect, reset, restore } from './App.actions'
import { showToaster } from './App.components/Toaster/Toaster.actions'
import { ERROR } from './App.components/Toaster/Toaster.constants'

Expand All @@ -13,7 +13,19 @@ const discard = (error: any, _action: any, _retries: any) => {
if (response && response.error && typeof response.error === 'string') message = response.error
else if (response && typeof response === 'string') message = response

console.error('discard', response.status, response.error)

// Rename error
if (response.error === 'jwt expired' || response.error === 'jwt malformed') message = 'Session expired'

// Actions on server errors
if (response) store.dispatch<any>(showToaster(ERROR, message, 'Contact support if needed'))
if (response.error === 'Password expired') store.dispatch<any>(redirect('/forgot-password'))
if (response.error === 'jwt expired' || response.error === 'jwt malformed' || response.error === 'Not logged in') {
store.dispatch<any>(reset())
store.dispatch<any>(redirect('/login'))
}

if (!request) throw error
if (!response) return false
return 400 <= response.status && response.status < 500
Expand All @@ -32,17 +44,18 @@ export const storeOfflineConfig = {
persistOptions: {
blacklist: ['router'],
},
//returnPromises: true,
}

export const reduxOfflineThunkMiddleware = () => (storex: any) => (next: any) => (action: any) => {
export const reduxOfflineThunkMiddleware = () => (_: any) => (next: any) => (action: any) => {
if (action && action.type === 'Offline/JS_ERROR') console.error(action.meta.error)
const result = next(action)
if (action) next(action)

if (action.meta && action.meta.thunks && action.meta.thunks.length > 0) {
if (action && action.meta && action.meta.thunks && action.meta.thunks.length > 0) {
action.meta.thunks.forEach((thunk: any) => {
if (!!thunk) store.dispatch<any>(thunk)
})
}

return result
// return action ? next(action) : next()
}

0 comments on commit 5a0de27

Please sign in to comment.