Skip to content
This repository was archived by the owner on Nov 10, 2021. It is now read-only.

Commit d6bd1c1

Browse files
committed
Fix undefined token error
1 parent 269ad81 commit d6bd1c1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

server/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ const router = new Router({prefix: "/api/v1"})
1818
// Authentication
1919
const checkAuth = async (ctx, next) => {
2020
// Token should be "Authorization: Bearer <UUID>"
21-
const token = ctx.header.authorization.split(" ").pop()
21+
const auth = ctx.header.authorization
22+
if (!auth) {
23+
throw new Error() // TODO: Return HTTP error status
24+
}
25+
const token = auth.split(" ").pop()
2226
// Authentication (token to user)
2327
await knex.first("name").where("token", token).from("users")
2428
.then(username => {

0 commit comments

Comments
 (0)