Skip to content
Merged
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
16 changes: 13 additions & 3 deletions src/playstation/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ import { getNpServiceName } from './util/platforms';

const REFRESH_TOKEN = process.env.PLAYSTATION_REFRESH_TOKEN?.trim() ?? '';

async function getAuth(): Promise<any> {
let authPromise: Promise<psn.AuthTokensResponse> | null = null;

async function getAuth(): Promise<psn.AuthTokensResponse> {
if (!REFRESH_TOKEN) throw new Error('No refresh token provided.');
const auth = await psn.exchangeRefreshTokenForAuthTokens(REFRESH_TOKEN);
return auth;
if (!authPromise) {
authPromise = (async () => {
const authorization = await psn.exchangeRefreshTokenForAuthTokens(REFRESH_TOKEN);
return authorization;
})().catch((err) => {
authPromise = null;
throw err;
});
}
return authPromise;
}

export async function getProfile(
Expand Down