Do a REST request with a URL encoded body and a mime type "application/x-www-form-urlencoded" ? #56
Replies: 1 comment
-
As there is not any answer, the wrote an issue report.
The complete login method is the following convertUrlSeachParams(
userAuthentication: UserJwtAutenticiation,
): URLSearchParams {
const urlSearchParams = new URLSearchParams()
urlSearchParams.set('username', userAuthentication.username)
urlSearchParams.set('password', userAuthentication.password)
urlSearchParams.set('grant_type', userAuthentication.grant_type as string)
urlSearchParams.set('scope', userAuthentication.scope)
return urlSearchParams
},
async passwordLogin(
userAuthentication: UserJwtAutenticiation,
): Promise<FetchError | undefined> {
const params = this.convertUrlSeachParams(userAuthentication)
const { data, error, status } = await useAuth('/v1/login', {
method: 'post',
body: params.toString() as unknown as UserJwtAutenticiation,
headers: {
...URL_ENCODED_REQUEST_HEADER,
},
watch: false,
})
if (data.value && status.value !== 'error') {
this.bearer = data.value
this.isAuthenticated = true
if (typeof window !== 'undefined' && window?.localStorage) {
window.localStorage.setItem('access_token', data.value.access_token)
window.localStorage.setItem('token_type', data.value.token_type)
}
} else {
this.deleteSession()
}
return error.value as FetchError | undefined
}, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I try to create a request. My API is the following:
The generated API client is the following:
I created a Pinia store to call send the login:
When I call the login method, the body is in JSON and not URL encoded.
The request header is
The request body is :
It should be:
grant_type=password&username=me%mydomain.com&password=***
The response as a 422 HTTP error. The body is:
If y send an URL encoded string instead of an object in the body, the IDE linter detects that the format is not as expected.
How to URL encode propery the data with the NuxtOpenFetch API ?
Beta Was this translation helpful? Give feedback.
All reactions