-
-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
derive method doesn't work as a plugin #566
Comments
Specify derive as global |
Continues to happen for me with v1.0.9 and the |
Tried to quickly reproduce it with something simple but this worked fine in 1.0.11. Can you make something with const deviceDetect = new Elysia({ name: "device-detect" })
.derive({ as: "global" }, ({ request }) => {
let userAgent = request.headers.get('user-agent');
return { userAgent }
});
const auth = new Elysia({ name: "auth" })
.use(deviceDetect);
const controller = new Elysia()
.use(auth)
.get('/', ({ userAgent }) => userAgent) |
Close as #513 and no further discussion for 2 weeks. |
This seems to work for me: // auth.ts
export const account = new Elysia()
.use(bearer())
.use(access)
.derive({ as: 'scoped' }, async ({
bearer, jwtAccess,
}) => {
if (!bearer)
throw new ForbiddenError('Unauthorized.')
const access = await jwtAccess.verify(bearer)
if (!access)
throw new ForbiddenError('Unauthorized.')
return {
account: JSON.parse(access.id),
}
})
// page.ts
export default new Elysia({ prefix: '/page' })
.get('/', async ({ account }) => {
console.log(account)
return await Page.fetch(account)
})
// api.ts
import { account } from '@/auth'
import page from './page'
export default new Elysia({ prefix: '/api' })
.use(account)
.use(page) But for some reason i just couldn't get rid of the red squiggly in vscode under |
What version of Elysia.JS is running?
1.0.7
What platform is your computer?
Linux 5.15.146.1-microsoft-standard-WSL2 x86_64 x86_64
What steps can reproduce the bug?
Property 'userDevice' does not exist on type '{ body: { username: string; password: string; }; query: Record<string, string | undefined>; params: never; headers: Record<string, string | undefined>; cookie: Record<string, Cookie<...>>; ... 5 more ...; jwt: { ...; }; }'.
// device-detect.ts

// authentication.ts

// sign-in-route.ts

What is the expected behavior?
I want to get user device to store information about user device. But derive method doesn't work as a plugin
What do you see instead?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: