Is it possible to make unique sessions in Phoenix Framework?












0















I was trying to avoid to fight with race conditions because of having two or more sessions opened for the same user so, I was thinking about to have only one session opened for each user closing old ones when a new one is opened. Do you know how to achieve this in the best way?










share|improve this question


















  • 1





    It's not exactly clear what you're asking. Please post some of your relevant code, describe what you're trying to do in more detail and mention what you have attempted so far.

    – Sheharyar
    Nov 26 '18 at 0:43
















0















I was trying to avoid to fight with race conditions because of having two or more sessions opened for the same user so, I was thinking about to have only one session opened for each user closing old ones when a new one is opened. Do you know how to achieve this in the best way?










share|improve this question


















  • 1





    It's not exactly clear what you're asking. Please post some of your relevant code, describe what you're trying to do in more detail and mention what you have attempted so far.

    – Sheharyar
    Nov 26 '18 at 0:43














0












0








0








I was trying to avoid to fight with race conditions because of having two or more sessions opened for the same user so, I was thinking about to have only one session opened for each user closing old ones when a new one is opened. Do you know how to achieve this in the best way?










share|improve this question














I was trying to avoid to fight with race conditions because of having two or more sessions opened for the same user so, I was thinking about to have only one session opened for each user closing old ones when a new one is opened. Do you know how to achieve this in the best way?







elixir phoenix-framework






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 0:31









Manuel RubioManuel Rubio

205




205








  • 1





    It's not exactly clear what you're asking. Please post some of your relevant code, describe what you're trying to do in more detail and mention what you have attempted so far.

    – Sheharyar
    Nov 26 '18 at 0:43














  • 1





    It's not exactly clear what you're asking. Please post some of your relevant code, describe what you're trying to do in more detail and mention what you have attempted so far.

    – Sheharyar
    Nov 26 '18 at 0:43








1




1





It's not exactly clear what you're asking. Please post some of your relevant code, describe what you're trying to do in more detail and mention what you have attempted so far.

– Sheharyar
Nov 26 '18 at 0:43





It's not exactly clear what you're asking. Please post some of your relevant code, describe what you're trying to do in more detail and mention what you have attempted so far.

– Sheharyar
Nov 26 '18 at 0:43












1 Answer
1






active

oldest

votes


















1














Personally I think that would be a horrid user experience - I would not expect be "managed" in this way by an application. I would expect I can have multiple sessions for a single user id.



Secondly, you would need to consider the possibility that your application is horizontally scaled and therefore multiple app/Phoenix servers. Now you have to manage uniqueness of a "user" across a distributed environment.



If you pursue this strategy then Phoenix Presence provides a means to manage distributed state but ... these are not atomic actions, they are eventually consistent. So that will just create another race condition if you already have one.



Otherwise you are looking at a centralised session store which would mean a redis instance or a database of some kind.



Personally, as a user, I really don't like sites that work the way you propose so hopefully you can resolve the race condition instead.






share|improve this answer
























  • I think I've got the solution for that precisely creating a GenServer to store the user information and linked that to a name using my library github.com/altenwald/forseti anyway I'll check Phoenix Presence as well. Thnaks!

    – Manuel Rubio
    Nov 26 '18 at 23:04











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473404%2fis-it-possible-to-make-unique-sessions-in-phoenix-framework%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Personally I think that would be a horrid user experience - I would not expect be "managed" in this way by an application. I would expect I can have multiple sessions for a single user id.



Secondly, you would need to consider the possibility that your application is horizontally scaled and therefore multiple app/Phoenix servers. Now you have to manage uniqueness of a "user" across a distributed environment.



If you pursue this strategy then Phoenix Presence provides a means to manage distributed state but ... these are not atomic actions, they are eventually consistent. So that will just create another race condition if you already have one.



Otherwise you are looking at a centralised session store which would mean a redis instance or a database of some kind.



Personally, as a user, I really don't like sites that work the way you propose so hopefully you can resolve the race condition instead.






share|improve this answer
























  • I think I've got the solution for that precisely creating a GenServer to store the user information and linked that to a name using my library github.com/altenwald/forseti anyway I'll check Phoenix Presence as well. Thnaks!

    – Manuel Rubio
    Nov 26 '18 at 23:04
















1














Personally I think that would be a horrid user experience - I would not expect be "managed" in this way by an application. I would expect I can have multiple sessions for a single user id.



Secondly, you would need to consider the possibility that your application is horizontally scaled and therefore multiple app/Phoenix servers. Now you have to manage uniqueness of a "user" across a distributed environment.



If you pursue this strategy then Phoenix Presence provides a means to manage distributed state but ... these are not atomic actions, they are eventually consistent. So that will just create another race condition if you already have one.



Otherwise you are looking at a centralised session store which would mean a redis instance or a database of some kind.



Personally, as a user, I really don't like sites that work the way you propose so hopefully you can resolve the race condition instead.






share|improve this answer
























  • I think I've got the solution for that precisely creating a GenServer to store the user information and linked that to a name using my library github.com/altenwald/forseti anyway I'll check Phoenix Presence as well. Thnaks!

    – Manuel Rubio
    Nov 26 '18 at 23:04














1












1








1







Personally I think that would be a horrid user experience - I would not expect be "managed" in this way by an application. I would expect I can have multiple sessions for a single user id.



Secondly, you would need to consider the possibility that your application is horizontally scaled and therefore multiple app/Phoenix servers. Now you have to manage uniqueness of a "user" across a distributed environment.



If you pursue this strategy then Phoenix Presence provides a means to manage distributed state but ... these are not atomic actions, they are eventually consistent. So that will just create another race condition if you already have one.



Otherwise you are looking at a centralised session store which would mean a redis instance or a database of some kind.



Personally, as a user, I really don't like sites that work the way you propose so hopefully you can resolve the race condition instead.






share|improve this answer













Personally I think that would be a horrid user experience - I would not expect be "managed" in this way by an application. I would expect I can have multiple sessions for a single user id.



Secondly, you would need to consider the possibility that your application is horizontally scaled and therefore multiple app/Phoenix servers. Now you have to manage uniqueness of a "user" across a distributed environment.



If you pursue this strategy then Phoenix Presence provides a means to manage distributed state but ... these are not atomic actions, they are eventually consistent. So that will just create another race condition if you already have one.



Otherwise you are looking at a centralised session store which would mean a redis instance or a database of some kind.



Personally, as a user, I really don't like sites that work the way you propose so hopefully you can resolve the race condition instead.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 9:14









KipKip

37927




37927













  • I think I've got the solution for that precisely creating a GenServer to store the user information and linked that to a name using my library github.com/altenwald/forseti anyway I'll check Phoenix Presence as well. Thnaks!

    – Manuel Rubio
    Nov 26 '18 at 23:04



















  • I think I've got the solution for that precisely creating a GenServer to store the user information and linked that to a name using my library github.com/altenwald/forseti anyway I'll check Phoenix Presence as well. Thnaks!

    – Manuel Rubio
    Nov 26 '18 at 23:04

















I think I've got the solution for that precisely creating a GenServer to store the user information and linked that to a name using my library github.com/altenwald/forseti anyway I'll check Phoenix Presence as well. Thnaks!

– Manuel Rubio
Nov 26 '18 at 23:04





I think I've got the solution for that precisely creating a GenServer to store the user information and linked that to a name using my library github.com/altenwald/forseti anyway I'll check Phoenix Presence as well. Thnaks!

– Manuel Rubio
Nov 26 '18 at 23:04




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473404%2fis-it-possible-to-make-unique-sessions-in-phoenix-framework%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python