Restrict user from see other users automatically


How can we auto restrict user to see himself only in users list by auto creating User Permission for this user when signup.

I tried the following server script with after save but no success (mostly because the owner of the created user at the time of signup is Guest):

doc = frappe.get_doc({
doctype: ‘User Permission’,
allow: ‘User’,

Please help me