<commit_before>import { Router, Request, Response } from 'express';
import { ensureLoggedIn } from 'connect-ensure-login';
import User from '../datastore/User';
import logger from '../logger';

const revokeRouter = Router();

revokeRouter.get('/',
    (req: Request, res: Response) => {

        const user: User | undefined = req.user;

        res.render('revoke', {
            title: 'Revoke',
            user
        });
    });

revokeRouter.post('/', ensureLoggedIn('/auth/twitter'),
    async (req: Request, res:Response) => {

        const user: User = req.user;

        try {
            await User.revoke(user);

            logger.debug('user revoked', user);

            res.render('revoke', {
                title: 'Revoke',
                revoked: true
            });

        } catch (err) {

            logger.error('fail revoke', err);

            res.render('revoke', {
                title: 'Revoke',
                err: true
            });
        }
    });

export default revokeRouter;<commit_msg>fix: destroy session in revoke<commit_after>import { Router, Request, Response } from 'express';
import { ensureLoggedIn } from 'connect-ensure-login';
import User from '../datastore/User';
import logger from '../logger';

const revokeRouter = Router();

revokeRouter.get('/',
    (req: Request, res: Response) => {

        const user: User | undefined = req.user;

        res.render('revoke', {
            title: 'Revoke',
            user
        });
    });

revokeRouter.post('/', ensureLoggedIn('/auth/twitter'),
    async (req: Request, res:Response) => {

        const user: User = req.user;

        try {
            // ユーザー情報を削除
            await User.revoke(user);

            if (req.session) {
                // セッションを削除
                req.session.destroy(err => {
                    logger.error(err);
                    res.render('revoke', {
                        title: 'Revoke',
                        err: true
                    });
                });
            }

            logger.debug('user revoked', user);

            res.render('revoke', {
                title: 'Revoke',
                revoked: true
            });

        } catch (err) {

            logger.error('fail revoke', err);

            res.render('revoke', {
                title: 'Revoke',
                err: true
            });
        }
    });

export default revokeRouter;
{'fraction_non_alphanumeric': 0.13891178895300907, 'fraction_numerical': 0.0, 'mean_word_length': 1.4994850669412976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4085913', 'n_tokens_mistral': 693, 'n_tokens_neox': 660, 'n_words': 152}