0
0
Fork 0

ログインできた

This commit is contained in:
Xeltica 2020-08-04 14:38:26 +09:00
parent 326384957c
commit dfbc06f858
18 changed files with 853 additions and 167 deletions

View file

@ -4,13 +4,16 @@ import { die } from './die';
import { v4 as uuid } from 'uuid';
import { config } from './config';
import axios from 'axios';
import { upsertUser, getUser, getUserCount } from './users';
export const router = new Router<DefaultState, Context>();
export const sessionHostCache: Record<string, string> = { };
router.get('/', async ctx => {
await ctx.render('index');
await ctx.render('welcome', {
usersCount: await getUserCount(),
});
});
router.get('/login', async ctx => {
@ -42,8 +45,17 @@ router.get('/miauth', async ctx => {
const url = `https://${host}/api/miauth/${session}/check`;
const { token, user } = (await axios.post(url)).data;
ctx.body = { ok: true, user };
if (!token || !user) {
await die(ctx, '問題が発生しました。お手数ですが、最初からやり直してください。');
}
await upsertUser(user.username, host, token);
const u = await getUser(user.username, host);
if (!u) {
await die(ctx, '問題が発生しました。お手数ですが、最初からやり直してください。');
}
await ctx.render('logined', { user: u });
});
router.get('/legacy-auth', async ctx => {