feat: Begins integrating database client into vapor app.

This commit is contained in:
2025-01-14 11:50:06 -05:00
parent c8bcffa0b5
commit ccf80f05a7
42 changed files with 2378 additions and 2540 deletions

View File

@@ -1,3 +1,5 @@
import DatabaseClientLive
import SharedModels
import Vapor
extension RoutesBuilder {
@@ -5,16 +7,19 @@ extension RoutesBuilder {
// Used to ensure views are protected, redirects users to the login page if they're
// not authenticated.
var protected: any RoutesBuilder {
#if DEBUG
return self
#else
return grouped(
User.credentialsAuthenticator(),
User.redirectMiddleware { req in
"login?next=\(req.url)"
}
)
#endif
// #if DEBUG
// return self
// #else
return grouped(
// User.credentialsAuthenticator(),
UserPasswordAuthenticator(),
UserTokenAuthenticator(),
UserSessionAuthenticator(),
User.redirectMiddleware { req in
"login?next=\(req.url)"
}
)
// #endif
}
func apiUnprotected(route: PathComponent) -> any RoutesBuilder {
@@ -24,15 +29,17 @@ extension RoutesBuilder {
// Allows basic or token authentication for api routes and prefixes the
// given route with "/api/v1".
func apiProtected(route: PathComponent) -> any RoutesBuilder {
#if DEBUG
return apiUnprotected(route: route)
#else
let prefixed = grouped("api", "v1", route)
return prefixed.grouped(
User.authenticator(),
UserToken.authenticator(),
User.guardMiddleware()
)
#endif
// #if DEBUG
// return apiUnprotected(route: route)
// #else
let prefixed = grouped("api", "v1", route)
return prefixed.grouped(
UserPasswordAuthenticator(),
UserTokenAuthenticator(),
// User.authenticator(),
// UserToken.authenticator(),
User.guardMiddleware()
)
// #endif
}
}