feat: add authentication

This commit is contained in:
2023-08-04 22:35:25 +02:00
parent f9638c35fc
commit 469db6525d
33 changed files with 492 additions and 100 deletions

View File

@ -1,7 +1,7 @@
import { HandlerContext, Handlers } from "$fresh/server.ts";
import { searchMovie } from "@lib/tmdb.ts";
import * as cache from "@lib/cache/cache.ts";
import { BadRequestError } from "@lib/errors.ts";
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
import { json } from "@lib/helpers.ts";
type CachedMovieQuery = {
@ -12,10 +12,15 @@ type CachedMovieQuery = {
const CACHE_INTERVAL = 1000 * 60 * 24 * 30;
const GET = async (
_req: Request,
_ctx: HandlerContext,
req: Request,
ctx: HandlerContext,
) => {
const u = new URL(_req.url);
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
const u = new URL(req.url);
const query = u.searchParams.get("q");