Welcome Guest, Not a member yet? Register   Sign In
Basic usage how-to for Shield authentication
#5

I was also looking for a way to remove users from Shield.

All I found was in the discussions this thread https://github.com/codeigniter4/shield/discussions/249 with a link to the migrations to setup the tables for users.

Given there is more than one table that references a user, it might be worth coming up with an SQL query that removes all records in the database related to a user.

Other than the users table (id), the foreign key is user_id.

Users Table
Auth Identities Table
Auth Login Attempts Table
Auth Token Login Attempts Table
Auth Remember Tokens (remember-me) Table
Groups Users Table
Users Permissions Table

From investigating, it seems when the tables were setup, it would be convenient to add a constraint of ON DELETE CASCADE so that user_id foreign key references in other child tables will be deleted in other tables when you delete the user in the users table.

I queried all the constraints in my database and cannot find any DELETE CASCADE so this is not setup.

In that case you will need to run multiple queries to remove the user from all tables.

For example, in phpmyadmin, I ran a SQL command that removes all users with an id in the users table thats more than 1. You could replace > 1 with a = 2 for example, to remove the user with id 2.

DELETE FROM users WHERE id > 1;
DELETE FROM auth_groups_users WHERE user_id > 1;
DELETE FROM auth_identities WHERE user_id > 1;
DELETE FROM auth_logins WHERE user_id > 1;
DELETE FROM auth_permissions_users WHERE user_id > 1;
DELETE FROM auth_remember_tokens WHERE user_id > 1;
DELETE FROM auth_token_logins WHERE user_id > 1;
Reply


Messages In This Thread
RE: Basic usage how-to for Shield authentication - by tbobker - 11-04-2022, 02:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB