export class CurrentRequest extends Context.Tag(
'astro-auth-prototype/lib/AstroRuntime/CurrentRequest'
)<CurrentRequest, Request>() {
static layerAstro = (Astro: AstroGlobal) => Layer.succeed(this, Astro.request)
}
export class CurrentUser extends Context.Tag(
'astro-auth-prototype/lib/AstroRuntime/CurrentUser'
)<CurrentUser, Option.Option<User>>() {
static layerAstro = (Astro: AstroGlobal) =>
Layer.effect(
this,
Effect.gen(function* () {
const auth = yield* Auth
return yield* auth.currentUser(Astro.request.headers)
})
)
}
export const defineAstroRuntime = (Astro: AstroGlobal) =>
ManagedRuntime.make(
Layer.mergeAll(
CurrentRequest.layerAstro(Astro),
CurrentUser.layerAstro(Astro).pipe(Layer.provide(Auth.Live))
)
)
export class CurrentRequest extends Context.Tag(
'astro-auth-prototype/lib/AstroRuntime/CurrentRequest'
)<CurrentRequest, Request>() {
static layerAstro = (Astro: AstroGlobal) => Layer.succeed(this, Astro.request)
}
export class CurrentUser extends Context.Tag(
'astro-auth-prototype/lib/AstroRuntime/CurrentUser'
)<CurrentUser, Option.Option<User>>() {
static layerAstro = (Astro: AstroGlobal) =>
Layer.effect(
this,
Effect.gen(function* () {
const auth = yield* Auth
return yield* auth.currentUser(Astro.request.headers)
})
)
}
export const defineAstroRuntime = (Astro: AstroGlobal) =>
ManagedRuntime.make(
Layer.mergeAll(
CurrentRequest.layerAstro(Astro),
CurrentUser.layerAstro(Astro).pipe(Layer.provide(Auth.Live))
)
)