Skip to content

Commit

Permalink
feat: client to delete spcp cookie (#2328)
Browse files Browse the repository at this point in the history
* feat: client to delete cookie

* chore: add env var for old domain name

* doc: add comment

* chore: add oldSpcpCookieDomain to environment

* fix: undefined cookieName
  • Loading branch information
tshuli authored Jul 8, 2021
1 parent a5e719f commit 360ac2a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/app/config/features/spcp-myinfo.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type ISpcpConfig = {
spCookieMaxAge: number
spCookieMaxAgePreserved: number
spcpCookieDomain: string
oldSpcpCookieDomain: string // TODO (#2329): To remove after old cookies have expired
cpCookieMaxAge: number
spIdpId: string
cpIdpId: string
Expand Down Expand Up @@ -76,6 +77,13 @@ const spcpMyInfoSchema: Schema<ISpcpMyInfo> = {
default: '',
env: 'SPCP_COOKIE_DOMAIN',
},
oldSpcpCookieDomain: {
// TODO (#2329): To remove after old cookies have expired
doc: 'Old domain name set on cookie that holds the SPCP jwt',
format: String,
default: '',
env: 'OLD_SPCP_COOKIE_DOMAIN',
},
cpCookieMaxAge: {
doc: 'Max CorpPass cookie age',
format: 'int',
Expand Down
3 changes: 3 additions & 0 deletions src/app/loaders/express/locals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const frontendVars = {
isCPMaintenance: spcpMyInfoConfig.isCPMaintenance, // Corppass maintenance message
GATrackingID: googleAnalyticsConfig.GATrackingID,
spcpCookieDomain: spcpMyInfoConfig.spcpCookieDomain, // Cookie domain used for removing spcp cookies
oldSpcpCookieDomain: spcpMyInfoConfig.oldSpcpCookieDomain, // Old cookie domain used for backward compatibility. TODO (#2329): Delete env var
}
const environment = ejs.render(
`
Expand All @@ -42,6 +43,8 @@ const environment = ejs.render(
var formsgSdkMode = "<%= formsgSdkMode%>"
// SPCP Cookie
var spcpCookieDomain = "<%= spcpCookieDomain%>"
// Old SPCP Cookie
var oldSpcpCookieDomain = "<%= oldSpcpCookieDomain%>"
`,
frontendVars,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ angular
function SpcpSession($interval, $q, Toastr, $window, $cookies) {
let session = {
userName: null,
cookieName: null,
rememberMe: null,
issuedAt: null,
cookieNames: {
Expand All @@ -41,6 +40,13 @@ function SpcpSession($interval, $q, Toastr, $window, $cookies) {
session.userName = undefined
},
logout: function (authType) {
$cookies.remove(
// TODO (#2329): To remove after old cookies have expired
session.cookieNames[authType],
$window.oldSpcpCookieDomain
? { domain: $window.oldSpcpCookieDomain }
: {},
)
$q.when(PublicFormAuthService.logoutOfSpcpSession(authType))
.then(() => {
$cookies.put('isJustLogOut', true)
Expand Down

0 comments on commit 360ac2a

Please sign in to comment.