├── .eslintrc.js ├── .github └── workflows │ ├── release.yaml │ └── test.yaml ├── .gitignore ├── .npmignore ├── .prettierrc.js ├── LICENSE ├── README.md ├── babel.config.json ├── package-lock.json ├── package.json ├── rollup.config.js ├── src ├── AuthContext.tsx ├── AuthContextForTesting.tsx ├── RequiredAuthProvider.tsx ├── hooks │ ├── additionalHooks.ts │ ├── useActiveOrg.tsx │ ├── useAuthInfo.ts │ ├── useAuthUrl.tsx │ ├── useHostedPageUrls.tsx │ ├── useLogoutFunction.ts │ └── useRedirectFunctions.tsx ├── index.test.js ├── index.tsx ├── useClientRef.tsx ├── withAuthInfo.tsx └── withRequiredAuthInfo.tsx └── tsconfig.json /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: true, 4 | es2021: true, 5 | }, 6 | extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:react/recommended"], 7 | overrides: [ 8 | { 9 | env: { 10 | node: true, 11 | }, 12 | files: [".eslintrc.{js,cjs}"], 13 | parserOptions: { 14 | sourceType: "script", 15 | }, 16 | }, 17 | ], 18 | parser: "@typescript-eslint/parser", 19 | parserOptions: { 20 | ecmaVersion: "latest", 21 | sourceType: "module", 22 | }, 23 | plugins: ["@typescript-eslint", "react"], 24 | ignorePatterns: ["node_modules/", "dist/"], 25 | rules: {}, 26 | } 27 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: npm publish 2 | on: 3 | release: 4 | types: [created] 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - uses: actions/setup-node@v2 11 | with: 12 | node-version: '16' 13 | registry-url: 'https://registry.npmjs.org' 14 | - run: npm install 15 | - run: npm test 16 | - run: npm publish 17 | env: 18 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 19 | -------------------------------------------------------------------------------- /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | name: npm test 2 | on: [push] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v2 8 | - uses: actions/setup-node@v2 9 | with: 10 | node-version: '16' 11 | registry-url: 'https://registry.npmjs.org' 12 | - run: npm install 13 | - run: npm test 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/intellij+all,vim,emacs,windows,macos,node 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=intellij+all,vim,emacs,windows,macos,node 4 | 5 | ### Emacs ### 6 | # -*- mode: gitignore; -*- 7 | *~ 8 | \#*\# 9 | /.emacs.desktop 10 | /.emacs.desktop.lock 11 | *.elc 12 | auto-save-list 13 | tramp 14 | .\#* 15 | 16 | # Org-mode 17 | .org-id-locations 18 | *_archive 19 | 20 | # flymake-mode 21 | *_flymake.* 22 | 23 | # eshell files 24 | /eshell/history 25 | /eshell/lastdir 26 | 27 | # elpa packages 28 | /elpa/ 29 | 30 | # reftex files 31 | *.rel 32 | 33 | # AUCTeX auto folder 34 | /auto/ 35 | 36 | # cask packages 37 | .cask/ 38 | dist/ 39 | 40 | # Flycheck 41 | flycheck_*.el 42 | 43 | # server auth directory 44 | /server/ 45 | 46 | # projectiles files 47 | .projectile 48 | 49 | # directory configuration 50 | .dir-locals.el 51 | 52 | # network security 53 | /network-security.data 54 | 55 | 56 | ### Intellij+all ### 57 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 58 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 59 | 60 | # User-specific stuff 61 | .idea/**/workspace.xml 62 | .idea/**/tasks.xml 63 | .idea/**/usage.statistics.xml 64 | .idea/**/dictionaries 65 | .idea/**/shelf 66 | 67 | # AWS User-specific 68 | .idea/**/aws.xml 69 | 70 | # Generated files 71 | .idea/**/contentModel.xml 72 | 73 | # Sensitive or high-churn files 74 | .idea/**/dataSources/ 75 | .idea/**/dataSources.ids 76 | .idea/**/dataSources.local.xml 77 | .idea/**/sqlDataSources.xml 78 | .idea/**/dynamic.xml 79 | .idea/**/uiDesigner.xml 80 | .idea/**/dbnavigator.xml 81 | 82 | # Gradle 83 | .idea/**/gradle.xml 84 | .idea/**/libraries 85 | 86 | # Gradle and Maven with auto-import 87 | # When using Gradle or Maven with auto-import, you should exclude module files, 88 | # since they will be recreated, and may cause churn. Uncomment if using 89 | # auto-import. 90 | # .idea/artifacts 91 | # .idea/compiler.xml 92 | # .idea/jarRepositories.xml 93 | # .idea/modules.xml 94 | # .idea/*.iml 95 | # .idea/modules 96 | # *.iml 97 | # *.ipr 98 | 99 | # CMake 100 | cmake-build-*/ 101 | 102 | # Mongo Explorer plugin 103 | .idea/**/mongoSettings.xml 104 | 105 | # File-based project format 106 | *.iws 107 | 108 | # IntelliJ 109 | out/ 110 | 111 | # VS Code 112 | .vscode 113 | 114 | # mpeltonen/sbt-idea plugin 115 | .idea_modules/ 116 | 117 | # JIRA plugin 118 | atlassian-ide-plugin.xml 119 | 120 | # Cursive Clojure plugin 121 | .idea/replstate.xml 122 | 123 | # Crashlytics plugin (for Android Studio and IntelliJ) 124 | com_crashlytics_export_strings.xml 125 | crashlytics.properties 126 | crashlytics-build.properties 127 | fabric.properties 128 | 129 | # Editor-based Rest Client 130 | .idea/httpRequests 131 | 132 | # Android studio 3.1+ serialized cache file 133 | .idea/caches/build_file_checksums.ser 134 | 135 | ### Intellij+all Patch ### 136 | # Ignores the whole .idea folder and all .iml files 137 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 138 | 139 | .idea/ 140 | 141 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 142 | 143 | *.iml 144 | modules.xml 145 | .idea/misc.xml 146 | *.ipr 147 | 148 | # Sonarlint plugin 149 | .idea/sonarlint 150 | 151 | ### macOS ### 152 | # General 153 | .DS_Store 154 | .AppleDouble 155 | .LSOverride 156 | 157 | # Icon must end with two \r 158 | Icon 159 | 160 | 161 | # Thumbnails 162 | ._* 163 | 164 | # Files that might appear in the root of a volume 165 | .DocumentRevisions-V100 166 | .fseventsd 167 | .Spotlight-V100 168 | .TemporaryItems 169 | .Trashes 170 | .VolumeIcon.icns 171 | .com.apple.timemachine.donotpresent 172 | 173 | # Directories potentially created on remote AFP share 174 | .AppleDB 175 | .AppleDesktop 176 | Network Trash Folder 177 | Temporary Items 178 | .apdisk 179 | 180 | ### Node ### 181 | # Logs 182 | logs 183 | *.log 184 | npm-debug.log* 185 | yarn-debug.log* 186 | yarn-error.log* 187 | lerna-debug.log* 188 | .pnpm-debug.log* 189 | 190 | # Diagnostic reports (https://nodejs.org/api/report.html) 191 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 192 | 193 | # Runtime data 194 | pids 195 | *.pid 196 | *.seed 197 | *.pid.lock 198 | 199 | # Directory for instrumented libs generated by jscoverage/JSCover 200 | lib-cov 201 | 202 | # Coverage directory used by tools like istanbul 203 | coverage 204 | *.lcov 205 | 206 | # nyc test coverage 207 | .nyc_output 208 | 209 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 210 | .grunt 211 | 212 | # Bower dependency directory (https://bower.io/) 213 | bower_components 214 | 215 | # node-waf configuration 216 | .lock-wscript 217 | 218 | # Compiled binary addons (https://nodejs.org/api/addons.html) 219 | build/Release 220 | 221 | # Dependency directories 222 | node_modules/ 223 | jspm_packages/ 224 | 225 | # Snowpack dependency directory (https://snowpack.dev/) 226 | web_modules/ 227 | 228 | # TypeScript cache 229 | *.tsbuildinfo 230 | 231 | # Optional npm cache directory 232 | .npm 233 | 234 | # Optional eslint cache 235 | .eslintcache 236 | 237 | # Microbundle cache 238 | .rpt2_cache/ 239 | .rts2_cache_cjs/ 240 | .rts2_cache_es/ 241 | .rts2_cache_umd/ 242 | 243 | # Optional REPL history 244 | .node_repl_history 245 | 246 | # Output of 'npm pack' 247 | *.tgz 248 | 249 | # Yarn Integrity file 250 | .yarn-integrity 251 | 252 | # dotenv environment variables file 253 | .env 254 | .env.test 255 | .env.production 256 | 257 | # parcel-bundler cache (https://parceljs.org/) 258 | .cache 259 | .parcel-cache 260 | 261 | # Next.js build output 262 | .next 263 | out 264 | 265 | # Nuxt.js build / generate output 266 | .nuxt 267 | dist 268 | 269 | # Gatsby files 270 | .cache/ 271 | # Comment in the public line in if your project uses Gatsby and not Next.js 272 | # https://nextjs.org/blog/next-9-1#public-directory-support 273 | # public 274 | 275 | # vuepress build output 276 | .vuepress/dist 277 | 278 | # Serverless directories 279 | .serverless/ 280 | 281 | # FuseBox cache 282 | .fusebox/ 283 | 284 | # DynamoDB Local files 285 | .dynamodb/ 286 | 287 | # TernJS port file 288 | .tern-port 289 | 290 | # Stores VSCode versions used for testing VSCode extensions 291 | .vscode-test 292 | 293 | # yarn v2 294 | .yarn/cache 295 | .yarn/unplugged 296 | .yarn/build-state.yml 297 | .yarn/install-state.gz 298 | .pnp.* 299 | 300 | ### Vim ### 301 | # Swap 302 | [._]*.s[a-v][a-z] 303 | !*.svg # comment out if you don't need vector files 304 | [._]*.sw[a-p] 305 | [._]s[a-rt-v][a-z] 306 | [._]ss[a-gi-z] 307 | [._]sw[a-p] 308 | 309 | # Session 310 | Session.vim 311 | Sessionx.vim 312 | 313 | # Temporary 314 | .netrwhist 315 | # Auto-generated tag files 316 | tags 317 | # Persistent undo 318 | [._]*.un~ 319 | 320 | ### Windows ### 321 | # Windows thumbnail cache files 322 | Thumbs.db 323 | Thumbs.db:encryptable 324 | ehthumbs.db 325 | ehthumbs_vista.db 326 | 327 | # Dump file 328 | *.stackdump 329 | 330 | # Folder config file 331 | [Dd]esktop.ini 332 | 333 | # Recycle Bin used on file shares 334 | $RECYCLE.BIN/ 335 | 336 | # Windows Installer files 337 | *.cab 338 | *.msi 339 | *.msix 340 | *.msm 341 | *.msp 342 | 343 | # Windows shortcuts 344 | *.lnk 345 | 346 | # Yalc 347 | .yalc 348 | yalc.lock 349 | 350 | # End of https://www.toptal.com/developers/gitignore/api/intellij+all,vim,emacs,windows,macos,node 351 | 352 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PropelAuth/react/e577dfc77e8f33555684f76540dabed3aa6b6ab1/.npmignore -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | printWidth: 120, 3 | trailingComma: "es5", 4 | tabWidth: 4, 5 | semi: false, 6 | singleQuote: false, 7 | } 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 PropelAuth 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
( 44 | Component: React.ComponentType
,
45 | args?: WithAuthInfoArgs
46 | ): React.ComponentType ) => {
50 | const context = useContext(AuthContext)
51 | if (context === undefined) {
52 | throw new Error("withAuthInfo must be used within an AuthProvider or RequiredAuthProvider")
53 | }
54 |
55 | const { loading, authInfo, defaultDisplayWhileLoading, refreshAuthInfo, tokens } = context
56 |
57 | function displayLoading() {
58 | if (args?.displayWhileLoading) {
59 | return args.displayWhileLoading
60 | } else if (defaultDisplayWhileLoading) {
61 | return defaultDisplayWhileLoading
62 | }
63 | return (
14 | Component: React.ComponentType ,
15 | args?: WithRequiredAuthInfoArgs
16 | ): React.ComponentType ) => {
20 | const context = useContext(AuthContext)
21 | if (context === undefined) {
22 | throw new Error("withRequiredAuthInfo must be used within an AuthProvider or RequiredAuthProvider")
23 | }
24 |
25 | const { loading, authInfo, defaultDisplayIfLoggedOut, defaultDisplayWhileLoading, refreshAuthInfo, tokens } =
26 | context
27 |
28 | function displayLoading() {
29 | if (args?.displayWhileLoading) {
30 | return args.displayWhileLoading
31 | } else if (defaultDisplayWhileLoading) {
32 | return defaultDisplayWhileLoading
33 | }
34 | return