logout and info
This commit is contained in:
1 parent
4041d9827d
commit
7ea2c37116
9 files changed
+49
-34
No files matched your search
+7
-3
@@ -167,11 +167,8 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) {
|
||||
ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
|
||||
const { username } = ctx.request.body;
|
||||
const user = await pg.userFindId(ctx.state.user.id);
|
||||
|
||||
const wants = await discogs.wantListSync(username, user);
|
||||
|
||||
events.emit(Events.WantsAdded, wants);
|
||||
|
||||
ctx.response.body = wants;
|
||||
});
|
||||
|
||||
@@ -189,6 +186,13 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) {
|
||||
ctx.response.body = results;
|
||||
});
|
||||
|
||||
router.post('/auth/logout', async (ctx, next) => {
|
||||
ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
|
||||
ctx.logout();
|
||||
ctx.status = 200;
|
||||
ctx.body = { success: true };
|
||||
});
|
||||
|
||||
app.use(router.routes());
|
||||
|
||||
return {
|
||||
|
||||
@@ -47,6 +47,9 @@ export default function createDiscogs(log: Log, pg: Pg) {
|
||||
const results = await Promise.allSettled(releases.map(release => pg.wantCreate(release, user)));
|
||||
// @ts-ignore
|
||||
const additions = results.filter(r => r.status === 'fulfilled').map(r => r.value);
|
||||
|
||||
log.info(additions);
|
||||
|
||||
return additions;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ 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, 'incorrect login');
|
||||
|
||||
ctx.login(user);
|
||||
ctx.status = 200;
|
||||
ctx.body = {
|
||||
@@ -59,15 +58,6 @@ export default function authRouter(log, pg: Pg) {
|
||||
};
|
||||
});
|
||||
|
||||
authRouter.post('/logout', async (ctx, next) => {
|
||||
await passport.authenticate('local', (err, user, info, status) => {
|
||||
ctx.assert(user, 401, 'incorrect login');
|
||||
ctx.logout();
|
||||
ctx.status = 200;
|
||||
ctx.body = { success: true };
|
||||
})(ctx, next);
|
||||
});
|
||||
|
||||
authRouter.post('/register', async (ctx, next) => {
|
||||
const { discogs, email, password } = ctx.request.body;
|
||||
// fetch discogs data if they have it
|
||||
|
||||
Reference in new issue
Block a user