Skip to content

Is it possible to keep type safety in ElysiaJS when using seperate route files, espcially when using plugins(JWT)? #1116

Answered by mtt-artis
heinergiehl asked this question in Q&A
Discussion options

You must be logged in to vote

👋

You need to add jwt on every Elysia instance where jwt is need for type inference, Elysia will handle the deduplication for you.
https://elysiajs.com/essential/plugin#plugin-deduplication

// jwt.ts
export const jwtConfig = jwt({
  name: "jwt",
  secret: "Fischl von Luftschloss Narfidort",
})

// File1.ts
import { jwtConfig } from "./jwt.ts";

new Elysia()
  .use(jwtConfig)
  .get()
  .post();

// File2.ts
import { jwtConfig } from "./jwt.ts";

new Elysia()
  .use(jwtConfig)
  .get()
  .post();

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@heinergiehl
Comment options

@mtt-artis
Comment options

Answer selected by heinergiehl
@heinergiehl
Comment options

@heinergiehl
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants