Skip to content
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
4 changes: 1 addition & 3 deletions examples/cstg/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
$('#login_required').text(
sdk.isLoginRequired() || sdk.isLoginRequired() === undefined ? 'yes' : 'no'
);
$(`#has_opted_out`).text(
sdk.hasOptedOut() ? 'yes' : 'no'
);
$(`#has_opted_out`).text(sdk.hasOptedOut() ? 'yes' : 'no');
$('#update_counter').text(callbackCounter);
$('#identity_state').text(String(JSON.stringify(state, null, 2)));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
Expand Down
19 changes: 12 additions & 7 deletions src/sdkBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,20 @@ export abstract class SdkBase {
return this._initComplete;
}

/**
* Deprecated
*/
public isLoginRequired() {
return this.hasIdentity();
return !this.isIdentityAvailable();
}

/**
* @deprecated in version 3.10.0. Will remove in June 2025. Use isIdentityAvailable() instead.
**/
public hasIdentity() {
if (!this._initComplete) return undefined;
return !(this.isLoggedIn() || this._apiClient?.hasActiveRequests());
return !(this.isIdentityValid() || this._apiClient?.hasActiveRequests());
}

public isIdentityAvailable() {
return this.isIdentityValid() || this._apiClient?.hasActiveRequests();
}

public hasOptedOut() {
Expand Down Expand Up @@ -295,8 +299,9 @@ export abstract class SdkBase {
if (this.hasOptedOut()) this._callbackManager.runCallbacks(EventType.OptoutReceived, {});
}

private isLoggedIn() {
return this._identity && !hasExpired(this._identity.refresh_expires);
private isIdentityValid() {
const identity = this._identity ?? this.getIdentityNoInit();
return identity && !hasExpired(identity.refresh_expires);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed function since its private and this makes more sense. Also added the getIdentityNoInit because we can have an identity without initComplete from the recent SDK changes

}

private temporarilyUnavailable(identity: Identity | OptoutIdentity | null | undefined) {
Expand Down
Loading