I have a basic Ruby app that I am building with Sinatra, Datamapper and has user authentication using OAuth. When I receive the data back from the Oauth service, I save a record of a new user in an sqlite3 db.
What I don't know how to do is how to go about verifying the user record doesn't already exist on the user database table. I can use the user's unique id (uid) to cross check whether the uid is already stored, but I am just unsure where to do this.
I have 2 classes and a /callback route. The User class is the db model, and an Authentication class has assorted methods for connecting to the OAuth, and the /callback route which will have the Authentication.save method being called.
Should I be checking for an existing record within the Authentication.save method and return a boolean or something else? Create a new method in Authentication that would be like Authentication.exists? (and what would that look like?) Or should I be checking within the /callback route?
I apologize if this wasn't 100% clear, I am having a difficult time describing my issue and am an absolute Ruby beginner...