Skip to content

Commit

Permalink
adding protected procedure to the getMeRoute for trpc
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-bierman committed Feb 10, 2024
1 parent 418b879 commit 98650d0
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions server/src/controllers/user/getMe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getUserByTokenService } from '../../services/user/getUserByToken';
import { publicProcedure } from '../../trpc';
import { protectedProcedure } from '../../trpc';

/**
* Retrieves the user information and sends it as a response.
Expand All @@ -19,10 +19,7 @@ export const getMe = async (req, res) => {
};

export function getMeRoute() {
return publicProcedure.query(async (opts) => {
const authHeader = opts.ctx.req.headers.authorization;
const token = authHeader.split(' ')[1];
const user = getUserByTokenService(token);
return user;
return protectedProcedure.query((opts) => {
return opts.ctx.user;
});
}

0 comments on commit 98650d0

Please sign in to comment.