fix: app context and routing
This commit is contained in:
parent
c00249586d
commit
9b5cf32314
8 changed files with 7 additions and 52 deletions
|
|
@ -13,9 +13,6 @@ const { ApolloServer, AuthenticationError } = require('apollo-server-express')
|
|||
const _ = require('lodash/fp')
|
||||
const pify = require('pify')
|
||||
|
||||
const login = require('./services/login')
|
||||
const register = require('./routes/authentication')
|
||||
|
||||
const options = require('../options')
|
||||
const users = require('../users')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
const express = require('express')
|
||||
const router = express.Router()
|
||||
|
||||
const login = require('../services/login')
|
||||
const options = require('../../options')
|
||||
const T = require('../../time')
|
||||
|
||||
const NEVER = new Date(Date.now() + 100 * T.years)
|
||||
const hostname = options.hostname
|
||||
|
||||
const register = (req, res, next) => {
|
||||
const otp = req.query.otp
|
||||
const ua = req.headers['user-agent']
|
||||
const ip = req.ip
|
||||
|
||||
if (!otp) return next()
|
||||
|
||||
return login.register(otp, ua, ip)
|
||||
.then(r => {
|
||||
if (r.expired) return res.status(401).send('OTP expired, generate new registration link')
|
||||
|
||||
// Maybe user is using old registration key, attempt to authenticate
|
||||
if (!r.success) return next()
|
||||
|
||||
const cookieOpts = {
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
domain: hostname,
|
||||
sameSite: true,
|
||||
expires: NEVER
|
||||
}
|
||||
|
||||
const token = r.token
|
||||
req.token = token
|
||||
res.cookie('token', token, cookieOpts)
|
||||
res.sendStatus(200)
|
||||
})
|
||||
}
|
||||
|
||||
router.get('/register', register)
|
||||
|
||||
module.exports = router
|
||||
|
|
@ -20,11 +20,11 @@ import AppContext from 'src/AppContext'
|
|||
import Header from 'src/components/layout/Header'
|
||||
import Sidebar from 'src/components/layout/Sidebar'
|
||||
import TitleSection from 'src/components/layout/TitleSection'
|
||||
import ApolloProvider from 'src/pazuz/apollo/Provider'
|
||||
import { tree, hasSidebar, Routes, getParent } from 'src/pazuz/routing/routes'
|
||||
import { tree, hasSidebar, Routes, getParent } from 'src/routing/routes'
|
||||
import global from 'src/styling/global'
|
||||
import theme from 'src/styling/theme'
|
||||
import { backgroundColor, mainWidth } from 'src/styling/variables'
|
||||
import ApolloProvider from 'src/utils/apollo'
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
const whyDidYouRender = require('@welldone-software/why-did-you-render')
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import gql from 'graphql-tag'
|
|||
import React, { useContext, useState } from 'react'
|
||||
import { useHistory } from 'react-router-dom'
|
||||
|
||||
import { AppContext } from 'src/App'
|
||||
import AppContext from 'src/AppContext'
|
||||
import { Button } from 'src/components/buttons'
|
||||
import { CodeInput } from 'src/components/inputs/base'
|
||||
import { H2, P } from 'src/components/typography'
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import gql from 'graphql-tag'
|
|||
import * as R from 'ramda'
|
||||
import React, { useState, useContext } from 'react'
|
||||
|
||||
import { AppContext } from 'src/App'
|
||||
import AppContext from 'src/AppContext'
|
||||
import { Link } from 'src/components/buttons'
|
||||
import { Switch } from 'src/components/inputs'
|
||||
import TitleSection from 'src/components/layout/TitleSection'
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useContext } from 'react'
|
||||
import { Route, Redirect } from 'react-router-dom'
|
||||
|
||||
import { AppContext } from 'src/App'
|
||||
import AppContext from 'src/AppContext'
|
||||
|
||||
import { isLoggedIn } from './utils'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useContext } from 'react'
|
||||
import { Route, Redirect } from 'react-router-dom'
|
||||
|
||||
import { AppContext } from 'src/App'
|
||||
import AppContext from 'src/AppContext'
|
||||
|
||||
import { isLoggedIn } from './utils'
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import ResetPassword from 'src/pages/Authentication/ResetPassword'
|
|||
import Blacklist from 'src/pages/Blacklist'
|
||||
import Cashout from 'src/pages/Cashout'
|
||||
import Commissions from 'src/pages/Commissions'
|
||||
import ConfigMigration from 'src/pages/ConfigMigration'
|
||||
// import ConfigMigration from 'src/pages/ConfigMigration'
|
||||
import { Customers, CustomerProfile } from 'src/pages/Customers'
|
||||
import Dashboard from 'src/pages/Dashboard'
|
||||
import Funding from 'src/pages/Funding'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue