#Setting env.d.ts not fixing error with Locals interface for Middleware

3 messages · Page 1 of 1 (latest)

rancid juniper
#

I've set the values in my env.d.ts but for some reason it's not working, all I'm trying to do is pass data (that is for sure there so I know, I'm saving it to a persistentAtom right now but I want to be sure Astro has it, and I think Middleware is the best way to do that)

import { defineMiddleware } from "astro:middleware";
import { $getAllScenesUnfiltered, $currentScene } from "./store/scene";

export const onRequest = defineMiddleware(async (context, next) => {
    // Intercept response data from a request
    // optionally, transform the response by modifying `locals`
    // E.G. locals.title = "New Title"
    if (context.request.url.includes("/dashboard/scenes")) {
        const allScenesUnfiltered = await $getAllScenesUnfiltered();
        context.locals.allScenesUnfiltered = allScenesUnfiltered;
        return next();
    }
    return next();
    // return a Response or the result of calling next()
});

this should set the allScenesUnfiltered in my middleware if that's the correct request URL (looking at making that filtering more specific haha)

but in my env.d.ts I set

import { type Models } from "appwrite"
/// <reference types="astro/client" />
declare namespace App {
    interface Locals {
        allScenesUnfiltered: Models.Document[];
    }
}

which should work right? but I get a TypeError because it's undefined and in my editor it says it isn't a value

tawdry mothBOT
#
Quiet in here?

It looks like no-one has responded to your question yet. People might not be available right now or don’t know how to answer your question. Want an answer while you wait? Try asking our experimental bot in #1095492539085230272.

desert galleon
#

import { type Models } from "appwrite" does not work..