Skip to content

fix: @W-17758477 cli accepts a provided sid token for use during sites local dev #346

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

Merged
merged 2 commits into from
Feb 26, 2025
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@inquirer/select": "^2.4.7",
"@lwc/lwc-dev-server": "~11.5.0",
"@lwc/sfdc-lwc-compiler": "~11.5.0",
"@lwrjs/api": "0.16.8",
"@lwrjs/api": "0.16.9",
"@oclif/core": "^4.1.0",
"@salesforce/core": "^8.6.2",
"@salesforce/kit": "^3.1.6",
Expand Down
23 changes: 13 additions & 10 deletions src/shared/experience/expSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,20 @@ export class ExperienceSite {
* @returns sid token for proxied site requests
*/
public async setupAuth(): Promise<string> {
let sidToken = ''; // Default to guest user access only
let sidToken = '';
// Default to guest user access if specified
if (process.env.SITE_GUEST_ACCESS === 'true') return sidToken;

// Use environment variable for now if users want to just have guest access only
if (process.env.SITE_GUEST_ACCESS !== 'true') {
try {
const networkId = await this.getNetworkId();
sidToken = await this.getNewSidToken(networkId);
} catch (e) {
// eslint-disable-next-line no-console
console.error('Failed to establish authentication for site', e);
}
// Use a provided token if specified in environment variables
if (process.env.SID_TOKEN) return process.env.SID_TOKEN;

// Otherwise attempt to generate one based on the currently authenticated admin user
try {
const networkId = await this.getNetworkId();
sidToken = await this.getNewSidToken(networkId);
} catch (e) {
// eslint-disable-next-line no-console
console.error('Failed to establish authentication for site', e);
}

return sidToken;
Expand Down
Loading
Loading