I have a springboot web application and I am trying allow concurrent user activity on the same browser.
The login function has a member object with email and password attribute tied to a thymeleaf form. When the user logs in it displays information for that user.
The issue I have is when I log in as a second user in a new tab while still logged in as first user, when i add a change to the first user the details of the user are changed to the second users.
On the java side the issue is related to this part.
What's happening is when a new member signs in I check if the member exists in "database" and then pass the object to the model. The model uses this object to populate the fields.
@RequestMapping(method = RequestMethod.POST, path = "/profile")
public String signIn(@ModelAttribute MemberEmail memberEmail, Model model, @RequestHeader, HttpHeaders headers)
{
if(MemberDB.validate(memberEmail))
{
member = MemberDB.getMember(memberEmail.getEmail());
model.addAttribute("member", member);
return "home";
}
else
{
System.out.println("Login Failed");
return "redirect:/devshub";
}
}
In my thymeleaf, I have a function where users can enter a message and it is displayed on their profile.
This function takes the message input and displays it on the users profile but it also needs a member to populate the fields again because it returns to the "home"
@RequestMapping(method = RequestMethod.POST, path="/save")
public String saveMessage(@ModelAttribute Member m, Model model, @RequestHeader HttpHeaders headers)
{
member.setMessage(m.getMessage());
model.addAttribute("member", member);
return "home";
}
When i log in to two different accounts on different browsers, i think because it uses two different session ids, the correct member object is referenced for each account(by the session). However when using the same browser, when the member object is set to the second user, if i add a message as the first user, the message is added but the user information is switced to second users.
I'm thinking a possible solution could be to redirect without returning to home to when user object is already populated but still thinking of how I could do this as I would preferably not like to mess with session id's.