src_stores_AuthStore.ts.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title> src/stores/AuthStore.ts</title>
  7. <script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
  8. <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
  9. <script src="./build/entry.js"></script>
  10. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  11. <!--[if lt IE 9]>
  12. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  13. <![endif]-->
  14. <link href="https://fonts.googleapis.com/css?family=Roboto:100,400,700|Inconsolata,700" rel="stylesheet">
  15. <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
  16. <link type="text/css" rel="stylesheet" href="https://jmblog.github.io/color-themes-for-google-code-prettify/themes/tomorrow-night.min.css">
  17. <link type="text/css" rel="stylesheet" href="styles/app.min.css">
  18. <link type="text/css" rel="stylesheet" href="styles/iframe.css">
  19. <link type="text/css" rel="stylesheet" href="">
  20. <script async defer src="https://buttons.github.io/buttons.js"></script>
  21. </head>
  22. <body class="layout small-header">
  23. <div id="stickyNavbarOverlay"></div>
  24. <div class="top-nav">
  25. <div class="inner">
  26. <a id="hamburger" role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
  27. <span aria-hidden="true"></span>
  28. <span aria-hidden="true"></span>
  29. <span aria-hidden="true"></span>
  30. </a>
  31. <div class="logo">
  32. </div>
  33. <div class="menu">
  34. <div class="navigation">
  35. <a
  36. href="index.html"
  37. class="link"
  38. >
  39. API Documentation
  40. </a>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. <div id="main">
  46. <div
  47. class="sidebar "
  48. id="sidebarNav"
  49. >
  50. <nav>
  51. <h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Interfaces</h3><ul><li><a href="AddLandmarkProps.html">AddLandmarkProps</a></li><li><a href="CommentProps.html">CommentProps</a></li><li><a href="IdToken.html">IdToken</a></li><li><a href="IntroProps.html">IntroProps</a></li><li><a href="Landmark.html">Landmark</a></li><li><a href="LandmarkDetailsProps.html">LandmarkDetailsProps</a></li><li><a href="LandmarkPinProps.html">LandmarkPinProps</a></li><li><a href="LMComment.html">LMComment</a></li><li><a href="ProfileProps.html">ProfileProps</a></li><li><a href="RegisterProps.html">RegisterProps</a></li><li><a href="UserProfile.html">UserProfile</a></li></ul><h3>Components</h3><ul><li><a href="App.html">App</a></li><li><a href="Atlas.html">Atlas</a></li><li><a href="Comment.html">Comment</a></li><li><a href="PrimaryButton.html">PrimaryButton</a></li><li><a href="Profile.html">Profile</a></li><li><a href="SecondaryButton.html">SecondaryButton</a></li></ul><h3>Global</h3><ul><li><a href="global.html#IconStrings">IconStrings</a></li></ul></div><div class="category"><h2>Hooks</h2><h3>Namespaces</h3><ul><li><a href="useAuth.html">useAuth</a></li><li><a href="useLandmarks.html">useLandmarks</a></li><li><a href="useProfile.html">useProfile</a></li></ul></div><div class="category"><h2>Map</h2><h3>Interfaces</h3><ul><li><a href="UserLocation.html">UserLocation</a></li></ul><h3>Components</h3><ul><li><a href="AddLandmark.html">AddLandmark</a></li><li><a href="LandmarkDetails.html">LandmarkDetails</a></li><li><a href="LandmarkPin.html">LandmarkPin</a></li><li><a href="Map.html">Map</a></li></ul></div><div class="category"><h2>Navigation</h2><h3>Components</h3><ul><li><a href="AuthorizedNavigator.html">AuthorizedNavigator</a></li><li><a href="UnauthorizedNavigator.html">UnauthorizedNavigator</a></li></ul><h3><a href="global.html">Global</a></h3></div><div class="category"><h2>Stores</h2><h3>Classes</h3><ul><li><a href="AuthStore.html">AuthStore</a></li></ul></div><div class="category"><h2>Unauthorized</h2><h3>Components</h3><ul><li><a href="Intro.html">Intro</a></li><li><a href="UnauthorizedLayout.html">UnauthorizedLayout</a></li></ul><h3>Components / Registration</h3><ul><li><a href="RegisterMain.html">RegisterMain</a></li></ul></div>
  52. </nav>
  53. </div>
  54. <div class="core" id="main-content-wrapper">
  55. <div class="content">
  56. <header class="page-title">
  57. <p>Source</p>
  58. <h1>src/stores/AuthStore.ts</h1>
  59. </header>
  60. <section>
  61. <article>
  62. <pre class="prettyprint source linenums"><code>import { action, makeObservable, observable } from "mobx";
  63. import * as SecureStore from 'expo-secure-store';
  64. /**
  65. * Represents OIDC ID token.
  66. */
  67. export interface IdToken {
  68. sub: string
  69. }
  70. /**
  71. * A mobx store responsible for holding the current access token, refresh token and userId in memory and in Expo's [SecureStore]{@link https://docs.expo.dev/versions/latest/sdk/securestore/}.
  72. * Used by {@link Atlas}
  73. * @category Stores
  74. */
  75. class AuthStore {
  76. /**
  77. * A string representing the OAuth2 access token issued to the user when they authenticate. It is sent in the Authorization header of all subsequent XHR requests in order to use authorized API endpoints.
  78. * For more information on OAuth2 and OpenIdConnect, visit {@link https://openid.net/connect/} and {@link https://oauth.net/2/}.
  79. * @memberOf AuthStore
  80. */
  81. accessToken?: string | null = null;
  82. /**
  83. * A string representing the OAuth2 refresh token issued to the user when they authenticate. It is sent to the identity provider to retrieve a new access token when the previous access token expires.
  84. * @memberOf AuthStore
  85. */
  86. refreshToken?: string | null = null;
  87. /**
  88. * A string representing the OAuth2 refresh token issued to the user when they authenticate. It is used to retrieve the users information from the API and to link objects created by the user to the user.
  89. */
  90. userId?: string = undefined;
  91. /**
  92. * Constructor. Uses mobx's [makeObservable]{@linkcode https://mobx.js.org/observable-state.html} to register actions and observable elements.
  93. */
  94. constructor() {
  95. makeObservable(this, {
  96. accessToken: observable,
  97. refreshToken: observable,
  98. userId: observable,
  99. setAccessTokenAsync: action,
  100. setRefreshTokenAsync: action,
  101. setIdAsync: action,
  102. });
  103. }
  104. /**
  105. * Uses the given access token value to set {@linkcode accessToken} and the 'access' element in the secure store.
  106. */
  107. async setAccessTokenAsync(tokenValue: string | null) {
  108. this.accessToken = tokenValue;
  109. if (this.accessToken) {
  110. await SecureStore.setItemAsync('access', this.accessToken);
  111. }
  112. else
  113. {
  114. await SecureStore.deleteItemAsync('access');
  115. }
  116. }
  117. /**
  118. * Uses the given refresh token value to set {@linkcode refreshToken} and the 'refresh' element in the secure store.
  119. */
  120. async setRefreshTokenAsync(tokenValue: string | null) {
  121. this.refreshToken = tokenValue;
  122. if (this.accessToken) {
  123. await SecureStore.setItemAsync('refresh', this.accessToken);
  124. }
  125. else
  126. {
  127. await SecureStore.deleteItemAsync('refresh');
  128. }
  129. }
  130. /**
  131. * Uses the given user id value to set {@linkcode userId} and the 'id' element in the secure store.
  132. */
  133. async setIdAsync(id?: string) {
  134. this.userId = id;
  135. if (this.userId) {
  136. await SecureStore.setItemAsync('id', this.userId);
  137. }
  138. else
  139. {
  140. await SecureStore.deleteItemAsync('id');
  141. }
  142. }
  143. }
  144. export const authStore = new AuthStore();</code></pre>
  145. </article>
  146. </section>
  147. </div>
  148. <footer class="footer">
  149. <div class="content has-text-centered">
  150. <p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a></p>
  151. <p class="sidebar-created-by">
  152. <a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
  153. <a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
  154. </p>
  155. </div>
  156. </footer>
  157. </div>
  158. <div id="side-nav" class="side-nav">
  159. </div>
  160. </div>
  161. <script src="scripts/app.min.js"></script>
  162. <script>PR.prettyPrint();</script>
  163. <script src="scripts/linenumber.js"> </script>
  164. </body>
  165. </html>