amplify
amplify copied to clipboard
middleware for issue 617
Created middleware folder in amplify/server Created auth.js file in amplify/server/middleware
3 functions
- ensureAuthenticated to check if user is login/authenticated. If not redirect them to some login page
- ensureAdmin to check if user is login and is an admin. If not redirect to some login page
- ensureGuest to check user is not login/authenticated. If they are redirect them to some dashboard/profile
Areas that need work/review
- The redirect endpoints need to be updated accordingly
- ensureAdmin function won't work until some admin data is created in the DB. Logic will need to be updated.
To use require the middleware like below const { ensureAuth, ensureGuest, ensureAdmin } = require("../middleware/auth"); Router.get("some endpoint", choose a middleware here(ensureAuth, ensureGuest, ensureGuest), {rest of code logic}))
Hello there, thanks for opening your first Pull Request. Someone will review it soon.