Comments (2)
You could hook into the session fetch and then check if the user is blocked by using a database or KV store.
Example: ~/server/plugins/check-blocked.ts
export default defineNitroPlugin(() => {
sessionHooks.hook('fetch', async (session, event) => {
// Check if user is blocked (in DB or KV) using session.user.id for example
// If blocked clear the session and throw an error (or redirect to sign-in page)
if (blocked) {
await clearUserSession(event);
// Throw an error (401 probably)
throw createError({ ... })
// or a redirect?
return sendRedirect(event, '/sign-in');
}
});
});
Not sure if it works because it only checks on session fetch (so first page load?). I based it on the readme
In api routes you could create a middleware: ~/server/middleware/check-blocked.ts
export default defineEventHandler(async (event) => {
const session = await requireUserSession(event);
// Same check as in example above
}
I hope this gives you enough information?
from nuxt-auth-utils.
Thanks!
from nuxt-auth-utils.
Related Issues (20)
- Is session refresh implemented? HOT 14
- Does this module work in an SPA setting? HOT 2
- Github redirect uri not match. When i use https,how to deal with it? HOT 7
- How to write a unit test for nuxt middleware? HOT 1
- No session when fetching during SSR HOT 4
- [plugin node-resolve] Could not resolve import "nitropack/runtime" HOT 1
- Allow setting the domain of the cookie to change its scope
- Store basic data in DB
- Keep user logged in / Set user from Cookie HOT 2
- Google redirect_uri seems wrong HOT 5
- Calling `useUserSession` on AWS Lambda leads to 500 internal server error HOT 1
- Add PKCE functionality to support authentication in SPAs
- What is the right way to expose oauth to custom modules ? HOT 2
- Session not set on index.vue / middleware
- Support exclude specific routes from fetching session on prerendered pages HOT 2
- nuxt-auth-utils throws `Unauthorized (/api/_auth/session)` on any 404 page HOT 2
- yarn upgrade-interactive is not showing the new release version as latest HOT 2
- Keycloak Auth failing in production on setUserSession call
- Passkey integration
- Failed redirect authentication request to http://localhost/api/_auth/session on start
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuxt-auth-utils.