I am following the example for RavenDB Oauth and it seems like the standard practice here is to utilize a user name for generating the id key. This would require the user to input a username during registration and login.
I am looking to have to the authentication based on an email instead of a username, however I am running into a wall trying to figure out how to implement it properly.
I have implemented Oauth as follows
using (IDocumentSession Session = DataDocumentStore.Instance.OpenSession())
{
Session.Store(new AuthenticationUser
{
Name = Email,
Id = String.Format("Raven/Users/{0}", Email),
AllowedDatabases = new[] { "*" }
}.SetPassword(Password));
Session.SaveChanges();
return Session.Load(String.Format("Raven/Users/{0}", Email));
}
which would then allow us the authenticate the user using the following (given that email and password are the only data provided for login)
using (IDocumentSession Session = DataDocumentStore.Instance.OpenSession())
{
return Session.Load(String.Format("Raven/Users/{0}", Email)).ValidatePassword(Password);
}
The problem I am finding is that if I use the email as the document id key and the email changes, the document id and any documents referencing that id will all need to be changed.
However, if I use a RavenDB generated id (which would remain static even if the email changes) I cannot call Session.Load and will have to use Session.Query instead, which is not as optimized if I understand the documentation correctly.
So the question is, has anyone run into this before and (if so) can you provide a suggestion as to how I might accomplish this?
If the email can change, you can’t use it as the id.
You would need to first do a query by the id then do the rest using the id you got from the query