See, create, invite, ban and delete the users of a project in Studio or from your server.
#In Studio
Open the project and go to Authentication → Users. Search by e-mail or id, sort by creation or last sign-in, and open a user to see their identities, sessions and MFA factors. Actions:
- Add user with e-mail and password (optionally auto-confirmed; no e-mail is sent) or Invite by e-mail.
- Send password recovery, Send magic link or Copy recovery link.
- Change the e-mail address or password, confirm the e-mail, and edit the user's metadata (JSON).
- Ban for 1 hour, 24 hours, 7 days, 30 days or permanently, and Unban. Access tokens already issued work until they expire.
- Sign out everywhere ends all of the user's sessions.
- Delete the user (confirmed by typing).
#On a server
With the service_role key you can manage users from a server:
JavaScript
const admin = createClient('https://<project-ref>.p.stitchdb.com', '<service-role-key>')
const { data } = await admin.auth.admin.listUsers()
await admin.auth.admin.createUser({ email: '[email protected]', password: 'a-strong-password', email_confirm: true })
await admin.auth.admin.inviteUserByEmail('[email protected]')
await admin.auth.admin.updateUserById(userId, { ban_duration: '24h' }) // 'none' lifts the ban
const { data: link } = await admin.auth.admin.generateLink({ type: 'recovery', email: '[email protected]' })
await admin.auth.admin.deleteUser(userId)JavaScript
const { data } = await admin.auth.admin.listUsers({ page: 1, perPage: 50 })
const { data: { user } } = await admin.auth.admin.getUserById(userId)
await admin.auth.admin.updateUserById(userId, { app_metadata: { plan: 'pro' } })
await admin.auth.admin.generateLink({ type: 'magiclink', email: '[email protected]' })
await admin.auth.admin.mfa.listFactors({ userId })#In SQL
Users are rows in auth.users. Read them in SQL, and link your own tables to them with a foreign key; see Use the signed-in user in SQL.
SQL
select id, email, created_at, last_sign_in_at from auth.users order by created_at desc limit 20;