feat: auth middleware

- CORS headers
- Get all links that belong to user
This commit is contained in:
Juan Rodriguez
2024-05-13 22:34:35 +02:00
parent 0ad534065c
commit 7f2a27ec79
9 changed files with 50 additions and 22 deletions
+19
View File
@@ -0,0 +1,19 @@
module App::Middlewares
class Auth < Kemal::Handler
include App::Models
include App::Lib
exclude ["/api/ping", "/:slug"]
def call(env)
return call_next(env) if exclude_match?(env)
begin
user = Database.get_by!(User, api_key: env.request.headers["X-Api-Key"])
env.set "user", user
rescue exception
raise App::UnauthorizedException.new(env)
end
call_next(env)
end
end
end