feat: Begins views, login is currently not working.

This commit is contained in:
2025-01-06 17:28:43 -05:00
parent 5efed277a1
commit 35ca73e1b4
10 changed files with 109 additions and 15 deletions

View File

@@ -2,10 +2,36 @@ import Fluent
import Vapor
func routes(_ app: Application) throws {
app.get { req async throws in
try await req.view.render("index", ["title": "Hello Vapor!"])
let redirectMiddleware = User.redirectMiddleware { req in
"login?next=\(req.url.path)"
}
let protected = app.grouped(User.sessionAuthenticator(), redirectMiddleware, User.guardMiddleware())
let credentialsProtected = protected.grouped(User.credentialsAuthenticator())
app.get { req async throws in
try await req.view.render("index", ["title": "HHE - Purchase Orders"])
}
app.get("login") { req async throws in
req.logger.info("login")
return try await req.view.render("login")
}
credentialsProtected.post("login") { req async throws -> View in
req.logger.info("login POST")
return try await req.view.render("logged-in")
}
credentialsProtected.get("body") { req async throws in
req.logger.info("body")
return try await req.view.render("logged-in")
}
// app.get("index") { req async throws -> View in
//
// }
app.get("hello") { _ async -> String in
"Hello, world!"
}