Skip to content

Commit 88f2c70

Browse files
authored
Added instructions for running auth demo against emulator (#5725)
1 parent 7a5bc84 commit 88f2c70

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

packages/auth/demo/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,19 @@ yarn run demo
5858
This will compile all the files needed to run Firebase Auth, and start a Firebase server locally at
5959
[http://localhost:5000](http://localhost:5000).
6060

61+
## Running against Auth Emulator
62+
63+
The demo page by default runs against the actual Auth Backend. To run against the Auth Emulator with mocked endpoints, do the following:
64+
65+
1. (Optional) If you are running against local changes to the Auth Emulator (see [Firebase CLI Contributing Guide](https://github.com/firebase/firebase-tools/blob/master/CONTRIBUTING.md)), make sure that your version of `firebase-tools` is executing against your `npm link`’d repository and that you've built your local emulator changes with `npm run build`.
66+
67+
2. From `auth/demo`, locally initialize a Firebase project by running `firebase init`. When asked "Which Firebase features do you want to set up for this directory?", select "Emulators". When asked "Which Firebase emulators do you want to set up?", select "Authentication Emulator". This will create a `firebase.json` file.
68+
69+
3. Change the constants `USE_AUTH_EMULATOR` and `AUTH_EMULATOR_URL` in `auth/demo/src/index.js` to `true` and `http://localhost:{port}` where the auth `port` can be found in the `firebase.json` file.
70+
71+
4. To run the app locally and against the Auth Emulator, simply issue the following command in the `auth/demo` directory:
72+
73+
```bash
74+
yarn run demo:emulator
75+
```
76+

packages/auth/demo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../../.gitignore'",
1212
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../../.gitignore'",
1313
"demo": "rollup -c && firebase serve",
14+
"demo:emulator": "rollup -c && firebase emulators:start",
1415
"build": "rollup -c",
1516
"build:deps": "lerna run --scope @firebase/'{app,auth}' --include-dependencies build",
1617
"dev": "rollup -c -w"

packages/auth/demo/src/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ import {
6767
linkWithRedirect,
6868
reauthenticateWithRedirect,
6969
getRedirectResult,
70-
browserPopupRedirectResolver
70+
browserPopupRedirectResolver,
71+
connectAuthEmulator
7172
} from '@firebase/auth';
7273

7374
import { config } from './config';
@@ -80,6 +81,12 @@ import {
8081
logAtLevel_
8182
} from './logging';
8283

84+
/**
85+
* Constants that are used when connecting to the Auth Emulator.
86+
*/
87+
const USE_AUTH_EMULATOR = false;
88+
const AUTH_EMULATOR_URL = 'http://localhost:9099';
89+
8390
let app = null;
8491
let auth = null;
8592
let currentTab = null;
@@ -1643,6 +1650,10 @@ function initApp() {
16431650
log('Initializing app...');
16441651
app = initializeApp(config);
16451652
auth = getAuth(app);
1653+
if (USE_AUTH_EMULATOR) {
1654+
connectAuthEmulator(auth, AUTH_EMULATOR_URL);
1655+
}
1656+
16461657

16471658
tempApp = initializeApp(
16481659
{
@@ -1655,6 +1666,9 @@ function initApp() {
16551666
persistence: inMemoryPersistence,
16561667
popupRedirectResolver: browserPopupRedirectResolver
16571668
});
1669+
if (USE_AUTH_EMULATOR) {
1670+
connectAuthEmulator(tempAuth, AUTH_EMULATOR_URL);
1671+
}
16581672

16591673
// Listen to reCAPTCHA config togglers.
16601674
initRecaptchaToggle(size => {

0 commit comments

Comments
 (0)