feat: auto userdata fetch
fix: gql directives and overall minor fixes
This commit is contained in:
parent
3f6c0e6037
commit
9fa97725ec
22 changed files with 94 additions and 127 deletions
|
|
@ -11,13 +11,11 @@ const cookieParser = require('cookie-parser')
|
|||
const bodyParser = require('body-parser')
|
||||
const { ApolloServer, AuthenticationError } = require('apollo-server-express')
|
||||
const _ = require('lodash/fp')
|
||||
const pify = require('pify')
|
||||
|
||||
const options = require('../options')
|
||||
const users = require('../users')
|
||||
|
||||
const session = require('./middlewares/session')
|
||||
const authRouter = require('./routes/auth')
|
||||
const { AuthDirective } = require('./graphql/directives')
|
||||
const { typeDefs, resolvers } = require('./graphql/schema')
|
||||
|
||||
|
|
@ -86,7 +84,6 @@ app.use(cors({ credentials: true, origin: devMode && 'https://localhost:3001' })
|
|||
|
||||
app.use('/id-card-photo', serveStatic(idPhotoCardBasedir, { index: false }))
|
||||
app.use('/front-camera-photo', serveStatic(frontCameraBasedir, { index: false }))
|
||||
app.use(authRouter)
|
||||
|
||||
// Everything not on graphql or api/register is redirected to the front-end
|
||||
app.get('*', (req, res) => res.sendFile(path.resolve(__dirname, '..', '..', 'public', 'index.html')))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
const otplib = require('otplib')
|
||||
const bcrypt = require('bcrypt')
|
||||
const { AuthenticationError } = require('apollo-server-express')
|
||||
|
||||
const loginHelper = require('../../services/login')
|
||||
const T = require('../../../time')
|
||||
|
|
@ -27,7 +28,7 @@ function authenticateUser(username, password) {
|
|||
|
||||
const getUserData = context => {
|
||||
const lidCookie = context.req.cookies && context.req.cookies.lid
|
||||
if (!lidCookie) throw new authErrors.InvalidCredentialsError()
|
||||
if (!lidCookie) throw new AuthenticationError()
|
||||
|
||||
const user = context.req.session.user
|
||||
return user
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
bills: [Bill]
|
||||
bills: [Bill] @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
blacklist: [Blacklist]
|
||||
blacklist: [Blacklist] @auth
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
deleteBlacklistRow(cryptoCode: String!, address: String!): Blacklist
|
||||
insertBlacklistRow(cryptoCode: String!, address: String!): Blacklist
|
||||
deleteBlacklistRow(cryptoCode: String!, address: String!): Blacklist @auth
|
||||
insertBlacklistRow(cryptoCode: String!, address: String!): Blacklist @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
countries: [Country]
|
||||
languages: [Language]
|
||||
accountsConfig: [AccountConfig]
|
||||
countries: [Country] @auth
|
||||
languages: [Language] @auth
|
||||
accountsConfig: [AccountConfig] @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
currencies: [Currency]
|
||||
cryptoCurrencies: [CryptoCurrency]
|
||||
currencies: [Currency] @auth
|
||||
cryptoCurrencies: [CryptoCurrency] @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -54,12 +54,12 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
customers: [Customer]
|
||||
customer(customerId: ID!): Customer
|
||||
customers: [Customer] @auth
|
||||
customer(customerId: ID!): Customer @auth
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
setCustomer(customerId: ID!, customerInput: CustomerInput): Customer
|
||||
setCustomer(customerId: ID!, customerInput: CustomerInput): Customer @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
funding: [CoinFunds]
|
||||
funding: [CoinFunds] @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
machineLogs(deviceId: ID!, from: Date, until: Date, limit: Int, offset: Int): [MachineLog]
|
||||
machineLogsCsv(deviceId: ID!, from: Date, until: Date, limit: Int, offset: Int): String
|
||||
serverLogs(from: Date, until: Date, limit: Int, offset: Int): [ServerLog]
|
||||
serverLogsCsv(from: Date, until: Date, limit: Int, offset: Int): String
|
||||
machineLogs(deviceId: ID!, from: Date, until: Date, limit: Int, offset: Int): [MachineLog] @auth
|
||||
machineLogsCsv(deviceId: ID!, from: Date, until: Date, limit: Int, offset: Int): String @auth
|
||||
serverLogs(from: Date, until: Date, limit: Int, offset: Int): [ServerLog] @auth
|
||||
serverLogsCsv(from: Date, until: Date, limit: Int, offset: Int): String @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -43,12 +43,12 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
machines: [Machine]
|
||||
machine(deviceId: ID!): Machine
|
||||
machines: [Machine] @auth
|
||||
machine(deviceId: ID!): Machine @auth
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
machineAction(deviceId:ID!, action: MachineAction!, cashbox: Int, cassette1: Int, cassette2: Int, newName: String): Machine
|
||||
machineAction(deviceId:ID!, action: MachineAction!, cashbox: Int, cassette1: Int, cassette2: Int, newName: String): Machine @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
notifications: [Notification]
|
||||
alerts: [Notification]
|
||||
hasUnreadNotifications: Boolean
|
||||
notifications: [Notification] @auth
|
||||
alerts: [Notification] @auth
|
||||
hasUnreadNotifications: Boolean @auth
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
toggleClearNotification(id: ID!, read: Boolean!): Notification
|
||||
clearAllNotifications: Notification
|
||||
toggleClearNotification(id: ID!, read: Boolean!): Notification @auth
|
||||
clearAllNotifications: Notification @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const { gql } = require('apollo-server-express')
|
|||
|
||||
const typeDef = gql`
|
||||
type Mutation {
|
||||
createPairingTotem(name: String!): String
|
||||
createPairingTotem(name: String!): String @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
promoCodes: [PromoCode]
|
||||
promoCodes: [PromoCode] @auth
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
createPromoCode(code: String!, discount: Int!): PromoCode
|
||||
deletePromoCode(codeId: ID!): PromoCode
|
||||
createPromoCode(code: String!, discount: Int!): PromoCode @auth
|
||||
deletePromoCode(codeId: ID!): PromoCode @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
cryptoRates: JSONObject
|
||||
fiatRates: [Rate]
|
||||
cryptoRates: JSONObject @auth
|
||||
fiatRates: [Rate] @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@ const { gql } = require('apollo-server-express')
|
|||
|
||||
const typeDef = gql`
|
||||
type Query {
|
||||
accounts: JSONObject
|
||||
config: JSONObject
|
||||
accounts: JSONObject @auth
|
||||
config: JSONObject @auth
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
saveAccounts(accounts: JSONObject): JSONObject
|
||||
# resetAccounts(schemaVersion: Int): JSONObject
|
||||
saveConfig(config: JSONObject): JSONObject
|
||||
# resetConfig(schemaVersion: Int): JSONObject
|
||||
# migrateConfigAndAccounts: JSONObject
|
||||
saveAccounts(accounts: JSONObject): JSONObject @auth
|
||||
# resetAccounts(schemaVersion: Int): JSONObject @auth
|
||||
saveConfig(config: JSONObject): JSONObject @auth
|
||||
# resetConfig(schemaVersion: Int): JSONObject @auth
|
||||
# migrateConfigAndAccounts: JSONObject @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
uptime: [ProcessStatus]
|
||||
uptime: [ProcessStatus] @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Query {
|
||||
transactions(from: Date, until: Date, limit: Int, offset: Int, deviceId: ID): [Transaction]
|
||||
transactions(from: Date, until: Date, limit: Int, offset: Int, deviceId: ID): [Transaction] @auth
|
||||
transactionsCsv(from: Date, until: Date, limit: Int, offset: Int): String
|
||||
}
|
||||
`
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const { gql } = require('apollo-server-express')
|
|||
|
||||
const typeDef = gql`
|
||||
type Query {
|
||||
serverVersion: String!
|
||||
serverVersion: String! @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
const express = require('express')
|
||||
const router = express.Router()
|
||||
|
||||
const getUserData = function (req, res, next) {
|
||||
const lidCookie = req.cookies && req.cookies.lid
|
||||
if (!lidCookie) {
|
||||
res.sendStatus(403)
|
||||
return
|
||||
}
|
||||
|
||||
const user = req.session.user
|
||||
return res.status(200).json({ message: 'Success', user: user })
|
||||
}
|
||||
|
||||
router.get('/user-data', getUserData)
|
||||
|
||||
module.exports = router
|
||||
Loading…
Add table
Add a link
Reference in a new issue