From a3afcee9798daa48daa1e0150647e0da08385bd0 Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Sat, 10 Apr 2021 15:23:04 -0400 Subject: [PATCH] Add create_session method --- src/api.ts | 17 +++++++++++++++++ src/index.ts | 12 ++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/api.ts b/src/api.ts index 0d199ee..880174c 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,4 +1,5 @@ import { Router } from 'express'; +import { createSessionFromCodeAndProvider } from './auth'; import { getGroupByID, getPoolByID, @@ -147,3 +148,19 @@ router.post('/my_pools', (req, res) => { res.json({ status: 'success' }); } }); + +router.get('/create_session', (req, res) => { + res.send('hello'); +}); + +router.post('/create_session', (req, res) => { + const { code, provider } = req.body; + console.log('Creating session: code =', code, 'provider =', provider); + createSessionFromCodeAndProvider(code, provider) + .then((token) => { + res.json({ status: 'success', session_token: token }); + }) + .catch(() => { + res.json({ status: 'error' }); + }); +}); diff --git a/src/index.ts b/src/index.ts index 6ce018a..3832a78 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,8 @@ -import express from 'express'; -import dotenv from 'dotenv'; +import * as bodyParser from 'body-parser'; import cors from 'cors'; -import { users, groups } from './data'; +import dotenv from 'dotenv'; +import express from 'express'; +import * as api from './api'; dotenv.config({ path: '.env', @@ -9,7 +10,10 @@ dotenv.config({ const app = express(); -app.use(cors); +app.use(cors()); +app.use(bodyParser.json()); + +app.use('/api', api.router); ((port = process.env.APP_PORT || 5000) => { app.listen(port, () => void console.log(`Listening on port ${port}`));