Last active
June 23, 2025 13:15
-
-
Save daharon/fc5c9f459cb15c22fc5916463e21c543 to your computer and use it in GitHub Desktop.
Endpoint output types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dev.aharon.test.htmx_ | |
import zio.http.endpoint.Endpoint | |
import zio.ZIO | |
import zio.http.{Handler, MediaType, Method, Path, Response, Status, URL} | |
import zio.schema.Schema | |
object EmailPasswordAuth: | |
private val validEmailPassword = (email = "[email protected]", password = "1234") | |
final case class EmailPasswordForm(email: String, password: String) derives Schema | |
val endpoint = Endpoint(Method.POST / "login") | |
.in[EmailPasswordForm](MediaType.application.`x-www-form-urlencoded`) | |
.out[String](Status.TemporaryRedirect) | |
.out[String](Status.Unauthorized) | |
.implementHandler( | |
Handler.fromFunction { form => | |
if form.email == validEmailPassword.email && form.password == validEmailPassword.password | |
then Response.redirect(URL(Path("/app"))) | |
else Response.unauthorized("Authentication Failed") | |
} | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[error] -- [E007] Type Mismatch Error: .../src/main/scala/EmailPasswordAuth.scala:21:30 | |
[error] 21 | then Response.redirect(URL(Path("/app"))) | |
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
[error] | Found: zio.http.Response | |
[error] | Required: String | |
[error] -- [E007] Type Mismatch Error: .../src/main/scala/EmailPasswordAuth.scala:22:46 | |
[error] 22 | else Response.unauthorized("Authentication Failed") | |
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
[error] | Found: zio.http.Response | |
[error] | Required: String |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment