That's great! But do you have a way to send the firebase auth token on each request (not manually)?
You can achieve it like so, this way every endpoint you wrap your middleware with will have access to the user's uid and email. parseCookies is from nookies package
export function withAuth(handler: any) { return async (req: NextApiRequest, res: NextApiResponse) => { const cookies = parseCookies({ req }); const token = cookies.token; if (!token) return res.status(401).end("Not authenticated"); const { uid, email } = await auth.verifyIdToken(cookies.token); if (!uid || !email) { return res.status(401).end("Not a valid user"); } return handler({ ...req, uid, email }, res); }; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That's great! But do you have a way to send the firebase auth token on each request (not manually)?
You can achieve it like so, this way every endpoint you wrap your middleware with will have access to the user's uid and email. parseCookies is from nookies package