From reading the docs, using auth in a serverless function seems pretty straightforward.
In my fetch request, I just set the headers with the auth-provider and authorization values as per the docs.
For some reason, this results in an Authentication Error in requireAuth
export const requireAuth = ({ role } = {}) => {
if (!context.currentUser) {
console.log(context)
throw new AuthenticationError("You don't have permission to do that.")
}
...
Are the docs outdated? Or am I just reading them wrong? I also tried setting the auth-provider to jwt but that didn’t work either.
I’d appreciate it if anyone has dealt with auth in a serverless function before and could help out
And use getAuthenticationContext from @redwoodjs/api and then
import { context } from '@redwoodjs/api
and maybe set context.currentUser = to the result of getAuthenticationContext such as “decoded”. That is, the first value in the array that is returned [decoded, { type, schema, token }, { event, context }]
Or something very close to that.
Would you mind adding an issue here:
And I can assign it to myself as a task so I do not lose track.