A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

19 lines
555 B

  1. package writefreely
  2. // AuthenticateUser ensures a user with the given accessToken is valid. Call
  3. // it before any operations that require authentication or optionally associate
  4. // data with a user account.
  5. // Returns an error if the given accessToken is invalid. Otherwise the
  6. // associated user ID is returned.
  7. func AuthenticateUser(db writestore, accessToken string) (int64, error) {
  8. if accessToken == "" {
  9. return 0, ErrNoAccessToken
  10. }
  11. userID := db.GetUserID(accessToken)
  12. if userID == -1 {
  13. return 0, ErrBadAccessToken
  14. }
  15. return userID, nil
  16. }