-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is is possible to access data.body
when using middlewares?
#84
Comments
Also, the I've an issue opened for confirmation: #85 |
With a framework like Is is possible to achieve the same with this |
Hey there, in order to validate emails you should use the
Currently middleware support is limited, and you cannot access the itty-router-openapi doesn't support the |
@G4brym Sad to know that it won't be possible with this. :/ |
You can do middlewares the "old fashion", because the endpoints are all class based, you can just build a base class that does authentication and then extend your endpoint from there. otherwise you can still do authentication with the current middleware support here is a snipped taken from here export function getBearer(request: Request): null | string {
const authHeader = request.headers.get('Authorization')
if (!authHeader || authHeader.substring(0, 6) !== 'Bearer') {
return null
}
return authHeader.substring(6).trim()
}
export async function authenticateUser(request: Request, env: any, context: any) {
const token = getBearer(request)
let session
if (token) {
session = await context.qb.fetchOne({
tableName: 'users_sessions',
fields: '*',
where: {
conditions: [
'token = ?1',
'expires_at > ?2',
],
params: [
token,
new Date().getTime()
]
},
}).execute()
}
if (!token || !session.results) {
return new Response(JSON.stringify({
success: false,
errors: "Authentication error"
}), {
headers: {
'content-type': 'application/json;charset=UTF-8',
},
status: 401,
})
}
// set the user_id for endpoint routes to be able to reference it
env.user_id = session.results.user_id
}
...
// Authentication middleware
router.all('/api/*', authenticateUser) |
Hi,
I've the following code in which I'm trying to run a middleware on
data.body.email
but unable to do so, am I missing something or is it just possible withrequest
.index.js
./utils/email.js
./users/controller.js
The text was updated successfully, but these errors were encountered: