From bd6f9616eb5659476af9e0953f32013e1854dd08 Mon Sep 17 00:00:00 2001 From: Andrew Israel Date: Mon, 17 Jun 2024 00:43:58 -0700 Subject: [PATCH] Expose auth URL from client --- package.json | 2 +- src/client.ts | 9 +++++++++ src/tests/index.test.ts | 10 ++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8414888..1b50aae 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "git", "url": "https://github.com/PropelAuth/javascript" }, - "version": "2.0.17", + "version": "2.0.18", "keywords": [ "auth", "user", diff --git a/src/client.ts b/src/client.ts index 8425492..68403f8 100644 --- a/src/client.ts +++ b/src/client.ts @@ -163,6 +163,11 @@ export interface IAuthClient { * Cleanup the auth client if you no longer need it. */ destroy(): void + + /** + * Gets the auth URL. + */ + getAuthUrl(): string } export interface IAuthOptions { @@ -599,6 +604,10 @@ export function createClient(authOptions: IAuthOptions): IAuthClient { clearInterval(clientState.refreshInterval) } }, + + getAuthUrl() { + return authOptions.authUrl + }, } const onStorageChange = async function () { diff --git a/src/tests/index.test.ts b/src/tests/index.test.ts index 2f23270..6a662b4 100644 --- a/src/tests/index.test.ts +++ b/src/tests/index.test.ts @@ -1,10 +1,10 @@ /** * @jest-environment jsdom */ +import { DEFAULT_RETRIES } from "../fetch_retries" import { createClient } from "../index" import { OrgIdToOrgMemberInfo } from "../org" import { ok, ResponseStatus, setupMockFetch, UnauthorizedResponse, UnknownErrorResponse } from "./mockfetch.test" -import {DEFAULT_RETRIES} from "../fetch_retries"; const INITIAL_TIME_MILLIS = 1619743452595 const INITIAL_TIME_SECONDS = INITIAL_TIME_MILLIS / 1000 @@ -12,7 +12,7 @@ const INITIAL_TIME_SECONDS = INITIAL_TIME_MILLIS / 1000 beforeAll(() => { jest.useFakeTimers("modern") // @ts-ignore - global.setTimeout = jest.fn(cb => cb()); + global.setTimeout = jest.fn((cb) => cb()) }) beforeEach(() => { @@ -99,6 +99,12 @@ test("client works without ending slash", async () => { expectCorrectEndpointWasHit(mockFetch, "https://www.example.com/api/v1/refresh_token") }) +test("client gets auth URL back correctly", async () => { + let client = createClient({ authUrl: "https://www.example.com", enableBackgroundTokenRefresh: false }) + + expect(client.getAuthUrl()).toBe("https://www.example.com") +}) + test("client parses user correctly", async () => { const { mockFetch } = setupMockFetchThatReturnsAccessToken() let client = createClient({ authUrl: "https://www.example.com", enableBackgroundTokenRefresh: false })