elysiajs / elysia-jwt

Plugin for Elysia for using JWT Authentication
MIT License
38 stars 16 forks source link

Adding scopes or Roles/permissions #24

Open Master-Y0da opened 6 months ago

Master-Y0da commented 6 months ago

I'm trying to use this plugin...but can't find a way or configuration that enable the use of scopes asigned to the generated JWT...is this possible ?

thanks for your help!

justin13888 commented 5 months ago

I think you could just specify the payload using the schema field.

Here's a random example I had:

export const jwtRefreshSetup = new Elysia().use(jwt({
    name: 'jwtRefresh',
    alg: 'HS256',
    secret: 'fjdfkdjfdkfjdkjdkfjkfjkfjd',
    schema: t.Object({
        id: t.String(),
       scope: t.Array(t.Union([
            t.Literal('profile'),
            t.Literal('media'),
            t.Literal('admin'),
        ])),
    }),
    iss: JWT_ISSUER,
    exp: JWT_REFRESH_TOKEN_DURATION,
    type: 'refresh',
}));