Skip to content

Commit

Permalink
feat(authentication): add option scheme to useEmulator method (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
robingenz committed Oct 17, 2023
1 parent 56c62f3 commit 36bd3f7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-beds-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@capacitor-firebase/authentication': minor
---

feat(web): add option `scheme` to `useEmulator` method
9 changes: 5 additions & 4 deletions packages/authentication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1796,10 +1796,11 @@ An interface covering the possible persistence mechanism types.

#### UseEmulatorOptions

| Prop | Type | Description | Default | Since |
| ---------- | ------------------- | ------------------------------------ | ----------------- | ----- |
| **`host`** | <code>string</code> | The emulator host (e.g. `10.0.2.2`). | | 0.2.0 |
| **`port`** | <code>number</code> | The emulator port (e.g. `9099`). | <code>9099</code> | 0.2.0 |
| Prop | Type | Description | Default | Since |
| ------------ | ------------------- | --------------------------------------------- | ------------------- | ----- |
| **`host`** | <code>string</code> | The emulator host without any port or scheme. | | 0.2.0 |
| **`port`** | <code>number</code> | The emulator port. | <code>9099</code> | 0.2.0 |
| **`scheme`** | <code>string</code> | The emulator scheme. Only available for Web. | <code>"http"</code> | 5.2.0 |


#### PluginListenerHandle
Expand Down
18 changes: 15 additions & 3 deletions packages/authentication/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1019,18 +1019,30 @@ export interface UnlinkResult {
*/
export interface UseEmulatorOptions {
/**
* The emulator host (e.g. `10.0.2.2`).
* The emulator host without any port or scheme.
*
* @since 0.2.0
* @example "127.0.0.1"
*/
host: string;
/**
* The emulator port (e.g. `9099`).
* The emulator port.
*
* @default 9099
* @since 0.2.0
* @default 9099
* @example 9099
*/
port?: number;
/**
* The emulator scheme.
*
* Only available for Web.
*
* @since 5.2.0
* @default "http"
* @example "https"
*/
scheme?: string;
}

/**
Expand Down
7 changes: 6 additions & 1 deletion packages/authentication/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,12 @@ export class FirebaseAuthenticationWeb
public async useEmulator(options: UseEmulatorOptions): Promise<void> {
const auth = getAuth();
const port = options.port || 9099;
connectAuthEmulator(auth, `${options.host}:${port}`);
const scheme = options.scheme || 'http';
if (options.host.includes('://')) {
connectAuthEmulator(auth, `${options.host}:${port}`);
} else {
connectAuthEmulator(auth, `${scheme}://${options.host}:${port}`);
}
}

private handleAuthStateChange(user: FirebaseUser | null): void {
Expand Down

0 comments on commit 36bd3f7

Please sign in to comment.