Dynamic role set after signup

Hello, im currently working on a new app in tabidoo platform and can’t find a solution to giving a role to a user after sign up… my current code is in workflow automations and no errors are logged in

(async (doo: IDoo) => { // do not change this line

    const userEmail = String(doo.model.login.value||'').trim().toLowerCase();
    if(!userEmail){
        return;
    }
    const existingEmployee= await doo.table.getCount("Employees",{
        filter:`email(eq)${userEmail}`
    })
    const roleName = (existingEmployee.data.count > 0)? 'employee':'company_admin';
    const roleRecords = await doo.table.getData<IDooApiTableRole>("Role",{filter:`name(eq)${roleName}`})
    if(!roleRecords ||roleRecords.data.length===0){
        return;
    }
    const foundRecord = roleRecords.data.at(0).id

    try{
      doo.model.role.setValue(foundRecord)
      
    }catch(e){
        console.log(e)

    }
}) // do not change this line

Any help would be really appreciated
Thanks

Hi,

you’re right — the workflow script you’re using can’t automatically assign a role “after sign-up” in the way you expect, because Tabidoo doesn’t have a direct “sign-up” trigger. Workflows always need an explicit trigger event.

The correct approach is to treat the creation of a new record in the “User” table as the moment when a user signs up.
Then you can use a workflow with the trigger “After record is created” on that table.

Inside that workflow, instead of using setValue, you need to update the record through updateFields

await doo.table.updateFields(“User”, doo.model.id, {
roles: { add: [roleId] }
});

Insert/Update multiple records
"links": {
    "add": ["64438767-45f0-40c1-b212-23df1a6eb8c3"],
    "remove": ["8f878e8f-1fda-4de4-9e6b-b5844dec7a43"]
}
  • add - array of ID records to add (optional)
  • remove - array of ID records to delete (optional)

link to documentation: Tabidoo API v.2 · Apiary