Skip to content

Commit 3ea1e1f

Browse files
authored
[Auth] Add Cordova demo app (#5067)
* Add a Cordova demo app' * Formatting * Add platform back
1 parent 36f0c20 commit 3ea1e1f

File tree

10 files changed

+2820
-0
lines changed

10 files changed

+2820
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
platforms/
2+
plugins/
3+
ul_web_hooks/
4+
src/config.js
5+
config.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "cordova-auth-demo",
3+
"displayName": "Cordova Auth Demo",
4+
"version": "1.0.0",
5+
"scripts": {
6+
"build:js": "rollup -c",
7+
"build:deps": "lerna run --scope @firebase/'{app-exp,auth-exp/cordova}' --include-dependencies build"
8+
},
9+
"keywords": [
10+
"ecosystem:cordova"
11+
],
12+
"devDependencies": {
13+
"cordova-android": "^9.1.0",
14+
"cordova-ios": "^6.2.0",
15+
"cordova-plugin-whitelist": "^1.3.4",
16+
"cordova-universal-links-plugin": "^1.2.1",
17+
"rollup": "^2.52.2"
18+
},
19+
"cordova": {
20+
"plugins": {
21+
"cordova-plugin-whitelist": {},
22+
"cordova-plugin-buildinfo": {},
23+
"cordova-universal-links-plugin": {},
24+
"cordova-plugin-browsertab": {},
25+
"cordova-plugin-inappbrowser": {},
26+
"cordova-plugin-customurlscheme": {
27+
"URL_SCHEME": "com.example.hello",
28+
"ANDROID_SCHEME": " ",
29+
"ANDROID_HOST": " ",
30+
"ANDROID_PATHPREFIX": "/"
31+
}
32+
},
33+
"platforms": [
34+
"ios",
35+
"android"
36+
]
37+
},
38+
"dependencies": {
39+
"@firebase/app-exp": "0.0.900",
40+
"@firebase/auth-exp": "0.0.900",
41+
"@firebase/logger": "0.2.6",
42+
"@firebase/util": "0.3.4",
43+
"cordova-plugin-browsertab": "0.2.0",
44+
"cordova-plugin-buildinfo": "4.0.0",
45+
"cordova-plugin-compat": "1.2.0",
46+
"cordova-plugin-customurlscheme": "5.0.2",
47+
"cordova-plugin-inappbrowser": "4.1.0",
48+
"cordova-universal-links-plugin-fix": "^1.2.1",
49+
"lerna": "^4.0.0",
50+
"tslib": "^2.1.0"
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
import resolve from '@rollup/plugin-node-resolve';
18+
import strip from '@rollup/plugin-strip';
19+
20+
/**
21+
* Common plugins for all builds
22+
*/
23+
const commonPlugins = [
24+
strip({
25+
functions: ['debugAssert.*']
26+
})
27+
];
28+
29+
const es5Builds = [
30+
/**
31+
* Browser Builds
32+
*/
33+
{
34+
input: 'src/index.js',
35+
output: [{ file: 'www/dist/bundle.js', format: 'esm', sourcemap: true }],
36+
plugins: [
37+
...commonPlugins,
38+
resolve({
39+
mainFields: ['module', 'main']
40+
})
41+
]
42+
}
43+
];
44+
45+
export default [...es5Builds];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<widget id="{{YOUR PACKAGE NAME / BUNDLE ID HERE}}" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
3+
<name>Cordova Auth Demo</name>
4+
<content src="index.html" />
5+
<access origin="*" />
6+
<allow-intent href="http://*/*" />
7+
<allow-intent href="https://*/*" />
8+
<universal-links>
9+
<host name="{{DYNAMIC LINK DOMAIN}}" scheme="https" />
10+
<host name="{{YOUR AUTH DOMAIN HERE}}" scheme="https">
11+
<path url="/__/auth/callback"/>
12+
</host>
13+
</universal-links>
14+
<preference name="AndroidLaunchMode" value="singleTask" />
15+
<preference name="android-minSdkVersion" value="22" />
16+
</widget>

0 commit comments

Comments
 (0)