12 lines
411 B
TypeScript
12 lines
411 B
TypeScript
|
import { createMiddleware } from 'hono/factory';
|
||
|
import jwt from 'jsonwebtoken';
|
||
|
export const getUserMiddleware = createMiddleware(async (c, next) => {
|
||
|
const Authorization = c.req.header('authorization');
|
||
|
console.log(Authorization);
|
||
|
const token = Authorization?.split(' ')[1] || '';
|
||
|
const users = jwt.decode(token) as any;
|
||
|
console.log(users);
|
||
|
c.set('user', users);
|
||
|
await next();
|
||
|
});
|