import { HttpApiMiddleware, HttpApiSecurity } from "@effect/platform"
import { Context, Data, Effect, Layer, Redacted } from "effect"
export class AuthenticationError extends Data.TaggedError<"AuthenticationError">(
"AuthenticationError",
)<{
message: string
}> {}
export class CurrentUser extends Context.Tag("CurrentUser")<
CurrentUser,
{
name: string
}
>() {}
export class Authentication extends HttpApiMiddleware.Tag<Authentication>()(
"Authentication",
{
provides: CurrentUser,
security: {
bearer: HttpApiSecurity.bearer,
},
},
) {}
export const AuthenticationLive = Layer.succeed(
Authentication,
Authentication.of({
bearer: (token) =>
Effect.gen(function* () {
if (token === "")
/* what to do here */
return {
name: Redacted.value(token),
}
}),
}),
)
import { HttpApiMiddleware, HttpApiSecurity } from "@effect/platform"
import { Context, Data, Effect, Layer, Redacted } from "effect"
export class AuthenticationError extends Data.TaggedError<"AuthenticationError">(
"AuthenticationError",
)<{
message: string
}> {}
export class CurrentUser extends Context.Tag("CurrentUser")<
CurrentUser,
{
name: string
}
>() {}
export class Authentication extends HttpApiMiddleware.Tag<Authentication>()(
"Authentication",
{
provides: CurrentUser,
security: {
bearer: HttpApiSecurity.bearer,
},
},
) {}
export const AuthenticationLive = Layer.succeed(
Authentication,
Authentication.of({
bearer: (token) =>
Effect.gen(function* () {
if (token === "")
/* what to do here */
return {
name: Redacted.value(token),
}
}),
}),
)