Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/misc #64

Merged
merged 3 commits into from
Nov 29, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/four-horses-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/federated-token-apollo": patch
---

minor optimalization when setting tokens
5 changes: 5 additions & 0 deletions .changeset/moody-geckos-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/federated-token-react": patch
---

throw exception on server error when refreshing token
5 changes: 5 additions & 0 deletions .changeset/proud-spies-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/federated-token": patch
---

Only serialize tokens when not empty
8 changes: 5 additions & 3 deletions packages/apollo/src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export class GatewayAuthPlugin<TContext extends PublicFederatedTokenContext>
const token = contextValue?.federatedToken;
const { req: request, res: response } = contextValue;

const isAuthenticated = token?.isAuthenticated() ?? false;

if (token?.shouldDestroyToken()) {
this.tokenSource.deleteAccessToken(request, response);
this.tokenSource.deleteRefreshToken(request, response);
Expand All @@ -122,7 +124,7 @@ export class GatewayAuthPlugin<TContext extends PublicFederatedTokenContext>
request,
response,
accessToken,
token.isAuthenticated(),
isAuthenticated,
);
}
}
Expand All @@ -134,7 +136,7 @@ export class GatewayAuthPlugin<TContext extends PublicFederatedTokenContext>
request,
response,
dataToken,
token.isAuthenticated(),
isAuthenticated,
);
}
}
Expand All @@ -145,7 +147,7 @@ export class GatewayAuthPlugin<TContext extends PublicFederatedTokenContext>
request,
response,
refreshToken,
token.isAuthenticated(),
isAuthenticated,
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class FederatedToken {
token.destroyToken = true;
}

if (!token) {
if (Object.keys(token).length < 1) {
return;
}
return Buffer.from(JSON.stringify(token)).toString("base64");
Expand Down Expand Up @@ -194,7 +194,7 @@ export class FederatedToken {
}

dumpRefreshToken(): string | undefined {
if (!this.refreshTokens) {
if (!this.refreshTokens || Object.keys(this.refreshTokens).length < 1) {
return;
}
return Buffer.from(JSON.stringify(this.refreshTokens)).toString("base64");
Expand Down