Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "git",
"url": "https://github.com/PropelAuth/javascript"
},
"version": "2.0.17",
"version": "2.0.18",
"keywords": [
"auth",
"user",
Expand Down
9 changes: 9 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -599,6 +604,10 @@ export function createClient(authOptions: IAuthOptions): IAuthClient {
clearInterval(clientState.refreshInterval)
}
},

getAuthUrl() {
return authOptions.authUrl
},
}

const onStorageChange = async function () {
Expand Down
10 changes: 8 additions & 2 deletions src/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/**
* @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

beforeAll(() => {
jest.useFakeTimers("modern")
// @ts-ignore
global.setTimeout = jest.fn(cb => cb());
global.setTimeout = jest.fn((cb) => cb())
})

beforeEach(() => {
Expand Down Expand Up @@ -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 })
Expand Down