Created
July 14, 2023 16:44
-
-
Save malerba118/f86f959ca3427d5ddc1d1d7da3271df9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// client | |
signIn().then((user) => { | |
axios.post('/users', user, { headers: { authorization: user.accessToken } }) | |
}) | |
// server | |
server.middleware((req, res) => { | |
if (req.headers.authorization) { | |
try { | |
const decoded = await firebase.verifyIdToken(req.headers.authorization) | |
req.uid = decoded.uid | |
} | |
catch(err) { | |
return res.status(401).json({ message: 'Unauthenticated' }) | |
} | |
} | |
}) | |
server.post('/users', async (req, res) => { | |
if (!req.uid) { | |
return res.status(401).json({ message: 'Unauthenticated' }) | |
} | |
else { | |
// create user in mongo if needed | |
} | |
}) | |
server.get('/books', async (req) => { | |
// return list regardless of auth | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment