css and some nav

This commit is contained in:
ntr committed 2022-08-10 23:47:33 +10:00
1 parent a8e5e5d7cd
commit 9a42c290ae
10 files changed
+273 -195

No files matched your search

+12 -12
View File
@@ -22,17 +22,17 @@ export default function createApi(log: Log, pg: Pg, discogs) {
const app = new koa();
const server = http.createServer(app.callback());
// app.use(async (ctx, next) => {
// try {
// await next();
// } catch (err) {
// log.error(err);
// ctx.status = err.statusCode || err.status || 500;
// ctx.body = {
// message: err.message
// };
// }
// });
app.use(async (ctx, next) => {
try {
await next();
} catch (err) {
log.error(err);
ctx.status = err.statusCode || err.status || 500;
ctx.body = {
error: err.message
};
}
});
const router = koaRouter();
@@ -128,7 +128,7 @@ export default function createApi(log: Log, pg: Pg, discogs) {
const { id } = ctx.request.params;
const user = await pg.userFindId(id);
// if (!user) return ctx.response.status = 404;
ctx.assert(user, 404, `user ${id} not found`);
const bundles = (await getBundles())
.map(b => {
-28
View File
@@ -1,28 +0,0 @@
import { KoaPassport } from 'koa-passport';
import { Strategy as LocalStrategy } from 'passport-local';
export default function authService(pg) {
const passport = new KoaPassport();
passport.serializeUser((user, done) => done(null, user.id));
passport.deserializeUser((id, done) => {
pg.userFindId(id)
.then(u => done(null, u))
.catch(e => done(e, null));
})
passport.use(new LocalStrategy(
{ usernameField: 'email '},
function localStrategy(email, password, done) {
pg.userFindEmail(email)
.then(user => {
if (!user) return done(null, false);
// if (!user.verifyPassword(password)) return done(null, false);
return done(null, user);
})
.catch(e => done(e, null));
}
));
return passport;
}
+4 -2
View File
@@ -38,7 +38,7 @@ export default function authRouter(log, pg: Pg) {
authRouter.post('/login', async (ctx, next) => {
await passport.authenticate('local', (err, user, info, status) => {
ctx.assert(user, 401, { error: 'incorrect login' });
ctx.assert(user, 401, 'incorrect login');
ctx.login(user);
ctx.status = 200;
@@ -50,11 +50,12 @@ export default function authRouter(log, pg: Pg) {
});
authRouter.get('/login', async (ctx, next) => {
ctx.assert(ctx.isAuthenticated(), 401, { error: 'log in required' });
ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
const user = ctx.state.user;
ctx.status = 200;
ctx.body = {
id: user.id,
email: user.email,
discogs: user.discogs,
};
@@ -68,6 +69,7 @@ export default function authRouter(log, pg: Pg) {
ctx.login(user);
ctx.status = 200;
ctx.body = {
id: user.id,
email: user.email,
discogs: user.discogs,
};