Create table after user registration with ownerId

Hi. I have such a problem, I have implemented login and registration in JS (react), I need a table to be created immediately after the user is registered and the ownerId value of the newly created user is present in it. In my current implementation, it is empty. If you create after login, then everything is fine. But I need it after registration. Is it possible to implement something like that somehow? Thanks

Hi @1116,

If you want to create records in table with certain user as their owner via from client side, then you must obtain auth token first. This can be done only during login. User registration operation only creates user without issuing such token.

Alternatively you can write event listener for afterRegister event in which your record will be created.
More information about events you can find by this link https://backendless.com/docs/bl-js/bl_event_handlers.html

Regards, Andriy

I solved this problem in another way. It did not work through registration, and since I needed to create this table once. I decided to do it through login. I created one more column (boolean) through the console and checked it at login. If True, then created a table and changed the value to False, if False, then do nothing.

const user = await Backendless.UserService.login(email, password, checked)

            const addCharacters = async (user) => {
                if (data.isCreate === true) {
                    const characters = {
                        name: 'Андрей',
                        gender: 'male'
                    }
                    return Backendless.Data.of('Characters').save(characters)
                }
            }

            const updateUser = (user) => {
                user.isCreate = false;
                return Backendless.UserService.update(user)
            }

            await Backendless.UserService.getCurrentUser().then(addCharacters)
            await Backendless.UserService.getCurrentUser().then(updateUser)

If anyone knows another way or can refactor my code, That would be good.

Hello @1116

You can use afterRegister handler in Business Logic:

  1. once a new user created you are able to login him in the Server Code using only its objectId
    Backendless.Users.login(userId: string, stayLoggedIn?: boolean)
  2. when the user is logged in you can create new objects and all of them will have ownerId equals to the user

Regards, Vlad

Thanks, I kind of found this in the console. I’m not completely torn yet, but I will try

Forgot to add, it’s all in react-native without nodeJs