-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store IP during signups, restrict tokens to IPs #1613
Comments
what if users switch between Wi-Fi and mobile data? won't it be a problem |
We can add the user's IP to the JWT payload when the user logs in and implement middleware to match the IP from the incoming request with the IP in the JWT payload. If they don't match, the user will be logged out |
Hey Harkirat, I was thinking to open this issue, but I noticed that you have already opened it. I also thought about the solution of restricting IPs to prevent multi-login. However, there is a problem: IPs often change. This means users would have to log in repeatedly whenever they switch networks, which might not be an ideal solution. I was researching on this some days ago and I have found a solution. We can use device and browser fingerprints to ensure that a device can only be logged in at a time by storing the device and browser's details. Such as resolution, user agent etc. this way we can make sure one user login at a time. I would love to work on it if you could assign this task to me. |
please check the pull request[ #1642 ]. I've added detailed explanation of what I am doing to resolve this issue. |
Fixes code100x#1613 Add IP address to JWT payload and session user during signups and logins. * **src/lib/auth.ts** - Add IP address to session user, token, and user interfaces. - Include IP address in JWT payload during signups and logins. - Retrieve user's IP address from request headers during authorization. - Store IP address in user object during login. * **src/middleware.ts** - Add IP address to user interface. - Check if the IP address matches the one in the JWT payload. - Redirect to invalid session page if IP address doesn't match. * **src/actions/user/index.ts** - Import FingerprintJS package. - Add function to store device and browser details during login. - Generate unique device ID using FingerprintJS. - Store device details in the user table. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/code100x/cms/issues/1613?shareId=XXXX-XXXX-XXXX-XXXX).
right now tokens can be shared and multiple people can login
Restricting by IP should help in protecting that
The text was updated successfully, but these errors were encountered: