Adding role profile to user via code

What I am doing basically is adding an user via a social login key , by default the user type is website user , and the user doesn’t have any roles assigned, I want to add a role profile with necessary permissions to the user on creation via a custom doctype which has a field linked to role profile, I tried to assign that role profile , I tried but both user is not getting user type system user and role profile is not getting applied to the user. Can someone help me

Just now with some changes in the code I am able to get user-type to system user but the role profile is still not getting applied to the user @NCP can you help me regarding this

Hii @nosob

please check once :

i hope this works for you

Hi @Manav_Mandli thanks for your help , it is not working, after some modifications to my code it is working