fix: Add a build system for the backend
This commit is contained in:
@@ -9,9 +9,8 @@ const authRouter = express.Router();
|
||||
|
||||
authRouter.use(bodyparser.json());
|
||||
authRouter.use(async (req, res, next) => {
|
||||
if ("token" in req.body || req.get("token")) {
|
||||
const token = req.body.token || req.get("token");
|
||||
|
||||
const token = req.get("Token");
|
||||
if (token) {
|
||||
// Check if were authenticated
|
||||
const auth = await isAuthenticated(token);
|
||||
if (auth)
|
||||
@@ -57,6 +56,9 @@ authRouter.get("/class/:id/topTen", async (req, res) => {
|
||||
});
|
||||
});
|
||||
authRouter.get("/level/:id/vocab", async (req, res) => {
|
||||
// TODO: Implement
|
||||
console.log("Stub: /auth/level/:id/vocab");
|
||||
|
||||
if (!req.params) {
|
||||
res.send({
|
||||
error: "400",
|
||||
@@ -67,8 +69,6 @@ authRouter.get("/level/:id/vocab", async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Stub: /auth/level/:id/vocab");
|
||||
// TODO: Implement
|
||||
res.send({
|
||||
error: "0",
|
||||
data: {
|
||||
@@ -94,13 +94,7 @@ app.use((req, res, next) => {
|
||||
// TODO: Change this to our domain
|
||||
res.append("Access-Control-Allow-Origin", "*");
|
||||
res.append("Access-Control-Allow-Headers", "Content-Type,Token");
|
||||
|
||||
if (res.method === "OPTIONS") {
|
||||
// TODO: Send 200
|
||||
res.end();
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
next();
|
||||
});
|
||||
app.use("/auth", authRouter);
|
||||
app.get("/health", (req, res) => {
|
||||
@@ -117,7 +111,7 @@ app.post("/login", async (req, res) => {
|
||||
console.log("Stub: /login");
|
||||
|
||||
// Check if all arguments were sent
|
||||
if (!body || !body.hasOwnProperty("username") || !body.hasOwnProperty("hash")) {
|
||||
if (!body || !("username" in body) || !("password" in body)) {
|
||||
res.send({
|
||||
error: "400",
|
||||
data: {
|
||||
@@ -129,8 +123,10 @@ app.post("/login", async (req, res) => {
|
||||
}
|
||||
|
||||
// Try to log the user in
|
||||
const userData = await performLogin(body.username, body.hash)
|
||||
const userData = await performLogin(body.username, body.password)
|
||||
.catch((err) => {
|
||||
console.log("Could not resolve login promise!", err);
|
||||
|
||||
// If anything was wrong, just tell the client
|
||||
res.send({
|
||||
error: "1",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { pbkdf2Sync } from "crypto";
|
||||
|
||||
import { IUser } from "shared/user";
|
||||
|
||||
export function isAuthenticated(token: string): Promise<boolean> {
|
||||
return new Promise((res, rej) => {
|
||||
// TODO
|
||||
@@ -7,7 +9,7 @@ export function isAuthenticated(token: string): Promise<boolean> {
|
||||
});
|
||||
}
|
||||
|
||||
export function performLogin(username: string, password: string): Promise<any | {}> {
|
||||
export function performLogin(username: string, password: string): Promise<IUser | {}> {
|
||||
return new Promise((res, rej) => {
|
||||
// Hash the password
|
||||
// TODO: Fetch the salt
|
||||
@@ -18,8 +20,9 @@ export function performLogin(username: string, password: string): Promise<any |
|
||||
res({
|
||||
username: "Polynom",
|
||||
uid: "1",
|
||||
showWelcome: false,
|
||||
showWelcome: true,
|
||||
classId: "test",
|
||||
score: 4,
|
||||
|
||||
sessionToken: "abc123",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user