ariandanim

ariandanim

How to make single login in phoenix framework?

Dear all,

I would like to make my SAAS aplication using only single login for every user email, I mean when they try to access using same email in another pc/laptop/mac they unable make it happen, it means like this scenario :

  1. PC A user A try to login (success)
  2. PC B user A try to login but make it unable login (they need to login again, but in PC A the user is log off/sign out)

Most Liked

psantos

psantos

Hi

Assuming you are using mix phx.gen.auth, a users_tokens table (Schema) is created. You can change it so that, when a user tries to login, to check this table is there is already a token for him. If yes, you can destroy it.

If you are not using phx.gen.auth, you can just follow the same strategy. Create a table to keep your users sessions, every time a user tries to login, check from this table if an existing session exist for this user.

psantos

psantos

Not sure what you mean. Which part of it would you like me to write?

For me, its not about the code. Its about the logic. And the logic is there. Persist the user session, when a user tries to login from different device ou web client, delete the previous persisted session.

Kinsua

Kinsua

And what do you do when they forget their password? You need email anyway to send them their new password or link to reset password. Or you can use an SMS or an external app, but given your problem with sharing emails, I doubt that mobile phone are not shared by many people as well ;D.

But if it’s like an intranet type of thing. For example, students that login with their IDs or some student card ID and some password you/department of the school or library or oganisation give them, why not. But then it would be best to implement it from scratch and forget the whole sending email and reseting thing altogether and the admin of that intranet website would be doing that manually or something when they reach for him or something.

Last Post!

arcyfelix

arcyfelix

Then adapt it to use whatever you want to use.
As I said, the generated files are a good starting point, not a “fits-all” solution.

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New

We're in Beta

About us Mission Statement