'I’m working on a backend using Deno and wondering if Authava works well with it out of the box. Any examples or gotchas I should know about?
Anon User 4
asked 5/13/2025
1 Answer
Yes — @authava/client
works seamlessly with Deno. It’s written in TypeScript and built with full ESM compatibility, so you can import it directly without needing any bundlers or compatibility hacks.
Here’s a real-world example of how we use Authava in a Deno app to handle cookie-based session validation:
import { AuthavaClient, AuthavaSession, AuthavaUser } from "@authava/client"
const sessionCache = new Map<
string,
{ session: Partial<AuthavaSession>; expiresAt: number }
>()
export const authMiddleware = async (ctx: any, next: () => Promise<unknown>) => {
const cookie = ctx.request.headers.get("cookie")
if (!cookie) {
ctx.response.status = 401
ctx.response.body = { error: "Unauthorized: No authentication provided" }
return
}
const cached = sessionCache.get(cookie)
if (cached?.expiresAt > Date.now()) {
ctx.state.user = cached.session.user
ctx.state.session = cached.session
return await ensureUserExists(ctx, next)
}
const session = await ctx.state.authava.getSession({ Cookie: cookie })
if (!session) {
ctx.response.status = 401
ctx.response.body = { error: "Unauthorized: Invalid session" }
return
}
sessionCache.set(cookie, {
session,
expiresAt: Date.now() + 300_000, // cache for 5 minutes
})
ctx.state.user = session.user
ctx.state.session = session
return await ensureUserExists(ctx, next)
}
🔐 Authava works great in Deno-based APIs and web services. You can validate sessions using standard Cookie headers and cache results to improve performance across your middleware.
Ryan Hein
answered 5/13/2025
Your Answer
You need to be logged in to answer this question.
Sign in to Answer