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
29 changes: 29 additions & 0 deletions app/services/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,33 @@ export default Service.extend({
window.addEventListener('focus', () => this.checkAuth());
},

/**
* Sets a domain-wide ( .travis-ci.com ) cookie indicating whether the user
* is currently signed in (1) or signed out (0). The cookie is consumed by
* the marketing / WordPress site to perform automatic redirects.
*
* Note: Cookie cannot be marked HttpOnly because it must be readable by
* client-side JavaScript on marketing pages.
*/
setSharedLoginCookie(isLoggedIn) {
try {
const host = window.location.hostname;
const cfg = config.loginStateCookie || {};
const name = cfg.name;
const days = cfg.expiryDays || 90;
const expires = new Date(Date.now() + days * 864e5).toUTCString();
const domainPart = /travis-ci\.com$/.test(host) ? '; Domain=.travis-ci.com' : '';
const securePart = window.location.protocol === 'https:' ? '; Secure' : '';
const value = isLoggedIn ? '1' : '0'; // (1=logged in,0=out)
document.cookie = `${name}=${value}; Expires=${expires}; Path=/${domainPart}${securePart}; SameSite=Lax`;
} catch (e) {}
},

clearSharedLoginCookie() {
this.setSharedLoginCookie(false);
},


checkAuth() {
if (!this.currentUser || !this.storage)
return;
Expand Down Expand Up @@ -141,6 +168,7 @@ export default Service.extend({
this.router.transitionTo('signin');
} catch (e) {}
}
this.clearSharedLoginCookie();
},

afterSignOut(callback) {
Expand Down Expand Up @@ -198,6 +226,7 @@ export default Service.extend({
this.set('state', STATE.SIGNED_IN);
Travis.trigger('user:signed_in', currentUser);
Travis.trigger('user:refreshed', currentUser);
this.setSharedLoginCookie(true);
})
.catch(error => {
if (!didCancel(error)) {
Expand Down
6 changes: 6 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ module.exports = function (environment) {
plans,
screens,
tailwind,
// login state cookie (used by marketing site for redirect decisions)
loginStateCookie: {
name: 'logged_in_to_app',
expiryDays:
parseInt(process.env.LOGGED_IN_TO_APP_COOKIE_EXPIRY, 10) || 90,
},
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/profile/billing-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ module('Acceptance | profile/billing', function (hooks) {
test('view billing on a manual plan with no invoices', async function (assert) {
this.subscription.source = 'manual';
this.subscription.status = undefined;
this.subscription.valid_to = new Date(2025, 7, 16).toISOString();
this.subscription.valid_to = new Date(2099, 1, 1).toISOString();

await profilePage.visit();
await profilePage.billing.visit();
Expand Down