Skip to content
Snippets Groups Projects
Commit 2d181388 authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

add ts-node-dev

parent cc1a519a
No related branches found
No related tags found
3 merge requests!24Auth, Profile, News, Entry Card, File management,!21update feature/news_api branch,!19Profile and Entry Card
......@@ -18,7 +18,11 @@ VSCode:
3. Run dev server
> ` npm run start-dev`
> `npm run start-dev`
or with `ts-node-dev` (recommended)
> `npm run dev`
To start with mongoDB
......
This diff is collapsed.
......@@ -7,7 +7,8 @@
"test": "jest src/tests/*",
"start-dev": "nodemon --config \"./nodemon.json\"/",
"build": "rm -rf ./build/ && tsc",
"start": "node build/index.js"
"start": "node build/index.js",
"dev": "ts-node-dev --respawn src/index.ts"
},
"author": "DevTeamSCH",
"license": "GPL-3.0-or-later",
......@@ -32,6 +33,7 @@
"express": "^4.17.1",
"express-session": "^1.17.0",
"mongoose": "^5.9.1",
"simple-oauth2": "^3.3.0"
"simple-oauth2": "^3.3.0",
"ts-node-dev": "^1.0.0"
}
}
import Profile, { Role } from "../../models/ProfileSchema";
import { Request, Response } from "express";
import { oauth2, scope } from "../../utils/auth";
import { authschResponse } from "../../utils/declarations/authschResponse";
import axios from "axios";
const complete = () => async (req: Request, res: Response) => {
const tokenConfig = {
code: req.query.code,
scope: scope,
redirect_uri: "",
};
try {
const token = await oauth2().authorizationCode.getToken(tokenConfig);
await axios
.get<authschResponse>(
`https://auth.sch.bme.hu/api/profile/?access_token=${token.access_token}`
)
.then((response) => {
Profile.findOne(
{ external_id: response.data.internal_id },
(error, profile) => {
if (error) {
console.warn(error);
return res.status(400);
} else {
if (!profile) {
const newProfile = new Profile();
newProfile.external_id = response.data.internal_id;
newProfile.email = response.data.mail;
newProfile.name = `${response.data.sn} ${response.data.givenName}`;
newProfile.save((err) => {
if (err) {
console.log(err);
return res.status(400);
}
});
}
}
}
);
req.session!.user = {
id: String(response.data.internal_id),
email: String(response.data.mail),
name: `${response.data.sn} ${response.data.givenName}`,
token,
};
})
.catch(function (error) {
console.log(error);
});
return res.redirect("/");
} catch (error) {
console.log("Access Token Error", error.message);
}
};
export default complete;
{
"ts-node": {
"files": true
},
"files": [
"./src/utils/declarations/response.d.ts",
"./src/utils/declarations/request.d.ts",
"./src/utils/declarations/session.d.ts",
"./src/utils/declarations/session.d.ts"
],
"compilerOptions": {
"module": "commonjs",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment