Finishing touches to publish
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,7 +2,7 @@ import Koa from 'koa';
|
||||
import Router from 'koa-router';
|
||||
import { StatusCodes } from 'http-status-codes';
|
||||
|
||||
import { ROUTE_PREFIX as prefix, RESET_ROUTE } from '../../constants/constants';
|
||||
import { ROUTE_PREFIX as prefix, RESET_ROUTE } from '../../constants/env';
|
||||
import Auth from '../../db/model/auth';
|
||||
import { sign } from '../../utils/jwt';
|
||||
import passport from '../passport';
|
||||
@@ -28,7 +28,7 @@ router.post('/login', async (ctx, next) => {
|
||||
});
|
||||
|
||||
router.post(process.env.RESET_ROUTE || RESET_ROUTE, async (ctx, next) => {
|
||||
const { token = null, password = null } = ctx.request.body as { token?: string, password?: string };
|
||||
const { token = null, password = null } = ctx.request.body as { token?: string; password?: string };
|
||||
if (token && password) {
|
||||
const loginToken = await Auth.resetPassword(token, password).catch();
|
||||
ctx.body({ token: loginToken });
|
||||
@@ -38,13 +38,11 @@ router.post(process.env.RESET_ROUTE || RESET_ROUTE, async (ctx, next) => {
|
||||
});
|
||||
|
||||
router.patch('/:record', (ctx: Koa.Context) => {
|
||||
const data = Auth.findOneAndUpdate(
|
||||
{ record: ctx.params.record },
|
||||
);
|
||||
const data = Auth.findOneAndUpdate({ record: ctx.params.record });
|
||||
if (!data) {
|
||||
ctx.throw(StatusCodes.NOT_FOUND);
|
||||
}
|
||||
ctx.body = { success: true, data };
|
||||
});
|
||||
|
||||
export { router as authRouter };
|
||||
export { router as authRouter };
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
const DB_USER = process.env.DB_USER || 'test';
|
||||
const DB_PASS = process.env.DB_PASSWORD || 'test';
|
||||
const DB_HOST = process.env.DB_HOST || 'mongodb';
|
||||
const DB_PORT = process.env.DB_PORT || 27017;
|
||||
const DB_NAME = process.env.DB_NAME || 'auth';
|
||||
|
||||
export const connection = mongoose.connect(`${DB_USER}:${DB_PASS}@${DB_HOST}:${DB_PORT}/${DB_NAME}`);
|
||||
@@ -1,8 +1,8 @@
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
import app from './app';
|
||||
import { connection } from './database/database.connection';
|
||||
import { PORT } from '../constants/constants';
|
||||
import { connection } from '../db';
|
||||
import { PORT } from '../constants/env';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Middleware } from 'koa';
|
||||
import { LOGIN_ROUTE } from '../../constants/constants';
|
||||
import { LOGIN_ROUTE } from '../../constants/env';
|
||||
|
||||
export const authenticated = (): Middleware => {
|
||||
return (ctx, next) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import passport from 'koa-passport';
|
||||
|
||||
import Auth from '../../model/auth';
|
||||
import Auth from '../../db/model/auth';
|
||||
import { Auth as AuthRecord } from '../../db/schema/auth';
|
||||
import LocalStrategy from './strategies/local';
|
||||
import JwtStrategy from './strategies/jwt';
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// eslint-disable-next-line import/named
|
||||
import { ExtractJwt, Strategy as JwtStrategy } from 'passport-jwt';
|
||||
|
||||
import Auth from '../../../model/auth';
|
||||
import { getJwtSecret } from '../../../utils/jwt';
|
||||
import Auth from '../../../db/model/auth';
|
||||
import { JWT_SECRET } from '../../../constants/env';
|
||||
|
||||
const opts = {
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
secretOrKey: getJwtSecret(),
|
||||
secretOrKey: JWT_SECRET,
|
||||
issuer: process.env.JWT_ISSUER,
|
||||
audience: process.env.JWT_AUDIENCE,
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// eslint-disable-next-line import/named
|
||||
import { Strategy as LocalStrategy } from 'passport-local';
|
||||
|
||||
import Auth from '../../../model/auth';
|
||||
import Auth from '../../../db/model/auth';
|
||||
|
||||
export default new LocalStrategy(async (username: string, password: string, done: any) => {
|
||||
const user = await Auth.findOne({
|
||||
|
||||
Reference in New Issue
Block a user