diff --git a/.env.example b/.env.example index e23c457..c34e2d5 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ -BASIC=basic_token \ No newline at end of file +USERNAME=basic_username +PASSWORD=basic_password \ No newline at end of file diff --git a/src/core/middleware/basic-authenticate.ts b/src/core/middleware/basic-authenticate.ts index 6038347..401c5b2 100644 --- a/src/core/middleware/basic-authenticate.ts +++ b/src/core/middleware/basic-authenticate.ts @@ -4,9 +4,10 @@ import { env } from 'node:process' class BasicAuthenticate implements Middleware { async handle (request: Request): Promise, Response>> { - const [type, credentials] = request.headers?.authorization?.split(' ') ?? [] + const [type, basicEncoded] = request.headers?.authorization?.split(' ') ?? [] if (type === 'Basic') { - if (credentials === env.BASIC) { + const [username, password] = Buffer.from(basicEncoded, 'base64').toString().split(':') + if (username === env.USERNAME && password === env.PASSWORD) { return right(ok({ message: 'Authenticated' })) } }