This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { transformUser } = require('./merge') | |
| module.exports = { | |
| users: async (args, context) => { | |
| try { | |
| return transformUser(context.user); | |
| } catch (err) { | |
| throw err; | |
| } | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const auth = require('./middlewares/auth').user; | |
| const { rootResolver, rootAuthResolver } = require('./graphql/resolvers/index'); | |
| app.use('/authApi', auth, graphqlHttp({ | |
| schema: graphQlSchema, | |
| rootValue: rootAuthResolver, | |
| graphiql: process.env.ALLOW_GRAPHIQL, | |
| })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const jwt = require('jsonwebtoken'); | |
| const User = require('../models/user'); | |
| module.exports.user = async function (req, res, next) { | |
| const token = req.header('x-auth-token'); | |
| if (!token) { | |
| return res.status(401).send('Access denied. No token provided.'); | |
| } | |
| try { | |
| const user = await User.findById(jwt.verify(token, process.env.JWT_KEY)._id); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const authResolver = require('./auth'); | |
| const userResolver = require('./users'); | |
| const rootResolver = { | |
| } | |
| const rootAuthResolver = { | |
| ...authResolver, | |
| ...userResolver, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express'); | |
| const bodyParser = require('body-parser'); | |
| const graphqlHttp = require('express-graphql'); | |
| const mongoose = require('mongoose'); | |
| const graphQlSchema = require('./graphql/schemas/index'); | |
| const { rootResolver, rootAuthResolver } = require('./graphql/resolvers/index'); | |
| const app = express(); | |
| const auth = require('./middlewares/auth').user; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const mongoose = require('mongoose'); | |
| const Schema = mongoose.Schema; | |
| const userSchema = new Schema({ | |
| firebase_uuid: { | |
| type: String, | |
| required: true | |
| }, | |
| }); |