Check for session token before accessing Library Account API
[sitka/overdrive-evergreen-opac.git] / src / od_api.coffee
index 7811f4c..a300c16 100644 (file)
@@ -214,7 +214,15 @@ define [
                #
                apiLibraryInfo: ->
 
-                       get = -> od.api session.links.libraries.href
+                       get = ->
+                               if session.token.token_type?
+                                       od.api session.links.libraries.href
+                               else
+                                       # We have no token of either kind. Let's default to getting
+                                       # a library access token.
+                                       od.apiDiscAccess()
+                                       .then get, logError
+                                       .then ok
 
                        ok = (x) ->
                                session.links.update x