aboutsummaryrefslogtreecommitdiffstats
path: root/authy.js
blob: 336cc2c54f6b28f0e28c0dd0812ed03d59366ad1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Client } from 'authy-client'
import config from './config'

const authy = new Client({ key: config.authy.key })

export default async user => {
  let { authyId } = user

  const res = await authy.createApprovalRequest({
    authyId: user.authyId,
    details: {
      visible: {
        User: user.name,
      }
    },
    logos: [{
      res: 'default',
      url: 'https://coinos.io/static/img/coinos.png'
    }],
    message: 'Login to CoinOS',
  }, {
    ttl: 120
  });

  let counter = 0

  return new Promise((resolve, reject) => {
    let poll = setInterval(async () => {
      counter++
      const r = await authy.getApprovalRequest({ id: res.approval_request.uuid });
      if (r.approval_request.status === 'approved') {
        clearInterval(poll)
        resolve(true)
      } 

      if (r.approval_request.status === 'denied')  {
        clearInterval(poll)
        resolve(false)
      } 

      if (counter > 60) { clearInterval(poll); reject(false) }
    }, 1000)
  })
} 
ight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
version: "3.6"
services:
  v2:
    container_name: v2
    build:
      context: .
      dockerfile: Dockerfile.dev
      args:
        URL: "${PUBLIC_COINOS_URL}"
        BTC: "${PUBLIC_BTC}"
        SOCKET: "${PUBLIC_SOCKET}"
    restart: always
    ports:
      - "3121:3121"
    environment:
      NODE_ENV: production
      ORIGIN: "${ORIGIN}"
      PORT: 3121
      STRIPE: "${STRIPE}"
      LAUNCH: "${LAUNCH}"
    extra_hosts:
      - host.docker.internal:host-gateway
networks:
  default:
    name: net
    external: true