|
| 1 | +# Cordova Auth Demo App |
| 2 | +This package contains a demo of the various Firebase Auth features bundled in |
| 3 | +an Apache Cordova app. |
| 4 | + |
| 5 | +## Dev Setup |
| 6 | + |
| 7 | +Follow [this guide](https://cordova.apache.org/docs/en/10.x/guide/cli/) to run |
| 8 | +set up Cordova CLI. tl;dr: |
| 9 | + |
| 10 | +```bash |
| 11 | +npm install -g cordova |
| 12 | +cordova requirements |
| 13 | +``` |
| 14 | + |
| 15 | +### Preparing the deps |
| 16 | + |
| 17 | +At this point you should have a basic environment set up that can support |
| 18 | +Cordova. Now you'll need to update some config files to make everything work. |
| 19 | +First, read through steps 1 - 5, 7 in the |
| 20 | +[Firebase Auth Cordova docs page](https://firebase.google.com/docs/auth/web/cordova) |
| 21 | +so that you get a sense of the values you need to add / adjust. |
| 22 | + |
| 23 | +Make a copy of `sample-config.xml` to `config.xml`, and replace the values |
| 24 | +outlined in curly braces. Notably, you'll need the package name / bundle ID |
| 25 | +of a registered app in the Firebase Console. You'll also need the Auth Domain |
| 26 | +that comes from the Web config. |
| 27 | + |
| 28 | +Next, you'll need to make a copy of `src/sample-config.js` to `src/config.js`, |
| 29 | +and you'll need to supply a Firebase JS SDK configuration in the form of that |
| 30 | +file. |
| 31 | + |
| 32 | +Once all this is done, you can get the Cordova setup ready in this specific |
| 33 | +project: |
| 34 | + |
| 35 | +```bash |
| 36 | +cordova prepare |
| 37 | +``` |
| 38 | + |
| 39 | +Work through any issues until no more errors are printed. |
| 40 | + |
| 41 | +## Building and running the demo |
| 42 | + |
| 43 | +The app consists of a bundled script, `www/dist/bundle.js`. This script is built |
| 44 | +from the `./src` directory. To change it, modify the source code in |
| 45 | +`src` and then rebuild the bundle: |
| 46 | + |
| 47 | +```bash |
| 48 | +# Build the deps the first time, and subsequent times if changing the core SDK |
| 49 | +npm run build:deps |
| 50 | +npm run build:js |
| 51 | +``` |
| 52 | + |
| 53 | +### Android |
| 54 | + |
| 55 | +You can now build and test the app on Android Emulator: |
| 56 | + |
| 57 | +```bash |
| 58 | +cordova build android |
| 59 | +cordova emulate android |
| 60 | + |
| 61 | +# Or |
| 62 | +cordova run android |
| 63 | +``` |
| 64 | + |
| 65 | +TODO: Any tips or gotchas? |
| 66 | + |
| 67 | +### iOS |
| 68 | + |
| 69 | +```bash |
| 70 | +cordova build ios |
| 71 | +cordova emulate ios |
| 72 | +``` |
| 73 | + |
| 74 | +Please ignore the command-line output mentioning `logPath` -- that file |
| 75 | +[will not actually exist](https://github.com/ios-control/ios-sim/issues/167) and |
| 76 | +won't contain JavaScript console logs. The Simulator app itself does not |
| 77 | +expose console logs either (System Log won't help). |
| 78 | + |
| 79 | +The recommended way around this is to use the remote debugger in Safari. Launch |
| 80 | +the Safari app on the same MacBook, and then go to Safari menu > Preferences > |
| 81 | +Advanced and check the "Show Develop menu in menu bar" option. Then, you should |
| 82 | +be able to see the Simulator under the Safari `Developer` menu and choose the |
| 83 | +app web view (Hello World > Hello World). This only works when the Simulator has |
| 84 | +already started and is running the Cordova app. This gives you full access to |
| 85 | +console logs AND uncaught errors in the JavaScript code. |
| 86 | + |
| 87 | +WARNING: This may not catch any JavaScript errors during initialization (or |
| 88 | +before the debugger was opened). If nothing seems working, try clicking the |
| 89 | +Reload Page button in the top-left corner of the inspector, which will reload |
| 90 | +the whole web view and hopefully catch the error this time. |
| 91 | + |
| 92 | +#### Xcode |
| 93 | + |
| 94 | +If you really want to, you can also start the Simulator via Xcode. Note that |
| 95 | +this will only give you access to console log but WON'T show JavaScript errors |
| 96 | +-- for which you still need the Safari remote debugger. |
| 97 | + |
| 98 | +```bash |
| 99 | +cordova build ios |
| 100 | +open ./platforms/ios/HelloWorld.xcworkspace/ |
| 101 | +``` |
| 102 | + |
| 103 | +Select/add a Simulator through the nav bar and click on "Run" to start it. You |
| 104 | +can then find console logs in the corresponding Xcode panel (not in the |
| 105 | +Simulator window itself). |
| 106 | + |
| 107 | +If you go this route, |
| 108 | +[DO NOT edit files in Xcode IDE](https://cordova.apache.org/docs/en/10.x/guide/platforms/ios/index.html#open-a-project-within-xcode). |
| 109 | +Instead, edit files in the `www` folder and run `cordova build ios` to copy the |
| 110 | +changes over (and over). |
| 111 | + |
| 112 | +### Notes |
| 113 | + |
| 114 | +You may need to update the cordova-universal-links-plugin `manifestWriter.js` |
| 115 | +to point to the correct Android manifest. For example: |
| 116 | + |
| 117 | +```js |
| 118 | +var pathToManifest = path.join(cordovaContext.opts.projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'AndroidManifest.xml'); |
| 119 | +``` |
0 commit comments