Restrict user from see other users automatically

Hello,

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’,
user: doc.name,
allow: ‘User’,
})
doc.insert()

Please help me