HTTP functions compatibility issue? with wix-users-backend

Hi Wixers -

I’m trying to get userId and pass it to an 3rd party API (disclosure: OneSignal). The setup is http request in the Custom code, coupled with a response in http-functions.js.

The problem is I can’t seem to get userId with wix-users-backend (see highlight below) . Are there some API that can’t be used within http-functions.js, or I’m missing something with my code here?

// calling with fetch( "https://my.domain/_functions/userToken" ) from Custom code embedded in the head

// http-functions.js
import { ok, notFound } from 'wix-http-functions'
import wixUsers from 'wix-users-backend'

let userId = wixUsers.currentUser.id

export function get_userToken(request) {
let response = {
"headers": {
"Content-Type": "application/json"
}
}

// userId is logging null for both declarations
// let userId = wixUsers.currentUser.id
console.log("userId", userId)
response.body = {
"token": token
}
return ok(response)
}

Any advice will be much appreciated :slight_smile:

As far as i am aware the HTTP Functions would not be user specific, meaning its not related to an actual site session and therefore is not actually utilising a certain user session, therefore would not have a Unique User ID.

Does the other end have a post function you could utilise instead? so upon site login or session start it would post the users ID?

Same probllem i am facing now, i can’t register inside the http-function, please help me how to solve this issue.

Here my code,

import wixUsersBackend from ‘wix-users-backend’ ;

export function doRegistration(email, password, firstName, lastName) {
// register the user

//return {“Status”:true,“Message”:email}

return wixUsersBackend.register(email, password, {
“contactInfo” : {
“firstName” : firstName,
“lastName” : lastName
}
})
.then((result) => {

return { “Status” : true , “Message” : “Successfully registered.” }

});

}

As I commented to your other post, please observe the community guidelines and refrain from multiple posts on the same topic or question.

The issue you are asking about here has been answered above. As Scott stated, " HTTP Functions would not be user specific, meaning its not related to an actual site session and therefore is not actually utilising a certain user session, "

This is an old post and is being closed.