Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
feat(src/server/api/auth): add auth route for server
Browse files Browse the repository at this point in the history
  • Loading branch information
Metnew committed Aug 4, 2017
1 parent 8dfaa54 commit e860567
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/server/api/auth/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import {Router} from 'express'
import jwt from 'jsonwebtoken'
import chalk from 'chalk'
// import validator from 'validator'
// {isLength, trim, isAlphanumeric, escape}
const router = Router()

// define the home page route
router.post('/', (req, res) => {
res.json({token: 'nothing'})
// const {username, password} = req.body
// const usernameValidated = validator.isLength(0, 36).is
// const passwordValidated =
const data = {username: 'cool_username_for_testing'}
jwt.sign(data, process.env.JWT_SECRET, (err, token) => {
if (err) {
throw new Error(
`Cant create JWT token based on input data: ${JSON.stringify(data)}`,
err
)
}
console.log(chalk.yellow(`Generated token for user: ${data.username}`))
res.json({token})
})
})

export default router

0 comments on commit e860567

Please sign in to comment.