export const isAuthedMiddleware = t.middleware(async ({ctx, next}) => {
const {req, res,} = ctx;
const token: string | undefined = req.headers.authorization?.split(" ")[1];
if (!token) {
throw new TRPCError({code: "UNAUTHORIZED"});
}
// my internal check function
if (await authCheckFunction(token) === null) {
throw new TRPCError({
code: "UNAUTHORIZED",
});
}
const {
userId,
sessionId, role
} = await anotherAuthCheckFunction(token, email);
return next({
ctx: {
userEmail: email,
userId,
role
},
});
});
export const isAuthedMiddleware = t.middleware(async ({ctx, next}) => {
const {req, res,} = ctx;
const token: string | undefined = req.headers.authorization?.split(" ")[1];
if (!token) {
throw new TRPCError({code: "UNAUTHORIZED"});
}
// my internal check function
if (await authCheckFunction(token) === null) {
throw new TRPCError({
code: "UNAUTHORIZED",
});
}
const {
userId,
sessionId, role
} = await anotherAuthCheckFunction(token, email);
return next({
ctx: {
userEmail: email,
userId,
role
},
});
});