Skip to content

Commit

Permalink
Merge branch 'feat/auth-checks-smoke-test' of github.com:dac09/redwoo…
Browse files Browse the repository at this point in the history
…d into feat/auth-checks-smoke-test

* 'feat/auth-checks-smoke-test' of github.com:dac09/redwood:
  fix(deps): update dependency esbuild to v0.14.27 (redwoodjs#4755)
  chore(deps): update dependency cypress to v9.5.2 (redwoodjs#4754)
  chore(deps): update dependency @types/lodash to v4.14.180 (redwoodjs#4751)
  fix(deps): update typescript-eslint monorepo to v5.15.0 (redwoodjs#4752)
  fix(deps): update dependency esbuild to v0.14.26 (redwoodjs#4747)
  Setup futureExpiresDate in constructor (redwoodjs#4742)
  chore(deps): update dependency @clerk/clerk-sdk-node to v2.9.10 (redwoodjs#4746)
  fix(deps): update dependency eslint-plugin-react to v7.29.4 (redwoodjs#4745)
  • Loading branch information
dac09 committed Mar 15, 2022
2 parents fd819cb + 90b637c commit 23ecbe3
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 183 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"babel-plugin-remove-code": "0.0.6",
"boxen": "5.1.2",
"core-js": "3.21.1",
"cypress": "9.5.1",
"cypress": "9.5.2",
"cypress-wait-until": "1.7.2",
"eslint": "8.11.0",
"fast-glob": "3.2.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"typescript": "4.6.2"
},
"peerDependencies": {
"@clerk/clerk-sdk-node": "2.9.9",
"@clerk/clerk-sdk-node": "2.9.10",
"@magic-sdk/admin": "1.3.4",
"firebase-admin": "10.0.2"
},
Expand Down
15 changes: 6 additions & 9 deletions packages/api/src/functions/dbAuth/DbAuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export class DbAuthHandler {
session: SessionRecord | undefined
sessionCsrfToken: string | undefined
corsContext: CorsContext | undefined
futureExpiresDate: string

// class constant: list of auth methods that are supported
static get METHODS(): AuthMethodNames[] {
Expand Down Expand Up @@ -214,13 +215,6 @@ export class DbAuthHandler {
return uuidv4()
}

// convert to the UTC datetime string that's required for cookies
get _futureExpiresDate() {
const futureDate = new Date()
futureDate.setSeconds(futureDate.getSeconds() + this.options.login.expires)
return futureDate.toUTCString()
}

// returns the Set-Cookie header to mark the cookie as expired ("deletes" the session)
get _deleteSessionHeader() {
return {
Expand All @@ -247,6 +241,9 @@ export class DbAuthHandler {
this.dbAccessor = this.db[this.options.authModelAccessor]
this.headerCsrfToken = this.event.headers['csrf-token']
this.hasInvalidSession = false
const futureDate = new Date()
futureDate.setSeconds(futureDate.getSeconds() + this.options.login.expires)
this.futureExpiresDate = futureDate.toUTCString()

if (options.cors) {
this.corsContext = createCorsContext(options.cors)
Expand Down Expand Up @@ -566,7 +563,7 @@ export class DbAuthHandler {
// returns all the cookie attributes in an array with the proper expiration date
//
// pass the argument `expires` set to "now" to get the attributes needed to expire
// the session, or "future" (or left out completely) to set to `_futureExpiresDate`
// the session, or "future" (or left out completely) to set to `futureExpiresDate`
_cookieAttributes({ expires = 'future' }: { expires?: 'now' | 'future' }) {
let meta

Expand Down Expand Up @@ -602,7 +599,7 @@ export class DbAuthHandler {
const expiresAt =
expires === 'now'
? DbAuthHandler.PAST_EXPIRES_DATE
: this._futureExpiresDate
: this.futureExpiresDate
meta.push(`Expires=${expiresAt}`)

return meta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ describe('dbAuth', () => {
})
})

describe('_futureExpiresDate', () => {
describe('futureExpiresDate', () => {
it('returns a date in the future as a UTCString', () => {
const dbAuth = new DbAuthHandler(event, context, options)

expect(dbAuth._futureExpiresDate).toMatch(UTC_DATE_REGEX)
expect(dbAuth.futureExpiresDate).toMatch(UTC_DATE_REGEX)
})
})

Expand Down Expand Up @@ -1300,7 +1300,7 @@ describe('dbAuth', () => {

expect(Object.keys(headers).length).toEqual(1)
expect(headers['Set-Cookie']).toMatch(
`;Path=/;HttpOnly;SameSite=Strict;Secure;Expires=${dbAuth._futureExpiresDate}`
`;Path=/;HttpOnly;SameSite=Strict;Secure;Expires=${dbAuth.futureExpiresDate}`
)
// can't really match on the session value since it will change on every render,
// due to CSRF token generation but we can check that it contains a only the
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@babel/cli": "7.16.7",
"@babel/core": "7.16.7",
"@clerk/clerk-js": "2.17.4",
"@clerk/clerk-sdk-node": "2.9.9",
"@clerk/clerk-sdk-node": "2.9.10",
"@clerk/types": "1.28.3",
"@supabase/supabase-js": "1.31.1",
"@types/netlify-identity-widget": "1.9.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"css-loader": "6.7.1",
"css-minimizer-webpack-plugin": "3.4.1",
"dotenv-webpack": "7.1.0",
"esbuild": "0.14.25",
"esbuild": "0.14.27",
"esbuild-loader": "2.18.0",
"fast-glob": "3.2.11",
"file-loader": "6.2.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"@babel/eslint-parser": "7.16.5",
"@babel/eslint-plugin": "7.16.5",
"@redwoodjs/internal": "0.49.1",
"@typescript-eslint/eslint-plugin": "5.14.0",
"@typescript-eslint/parser": "5.14.0",
"@typescript-eslint/eslint-plugin": "5.15.0",
"@typescript-eslint/parser": "5.15.0",
"eslint": "8.11.0",
"eslint-config-prettier": "8.5.0",
"eslint-import-resolver-babel-module": "5.3.1",
Expand All @@ -26,7 +26,7 @@
"eslint-plugin-jest-dom": "4.0.1",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-react": "7.29.3",
"eslint-plugin-react": "7.29.4",
"eslint-plugin-react-hooks": "4.3.0",
"prettier": "2.5.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"chalk": "4.1.2",
"core-js": "3.21.1",
"deepmerge": "4.2.2",
"esbuild": "0.14.25",
"esbuild": "0.14.27",
"fast-glob": "3.2.11",
"findup-sync": "5.0.0",
"fs-extra": "10.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/structure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@babel/cli": "7.16.7",
"@babel/core": "7.16.7",
"@types/fs-extra": "9.0.13",
"@types/lodash": "4.14.179",
"@types/lodash": "4.14.180",
"@types/lru-cache": "5.1.1",
"@types/node": "16.11.26",
"@types/vscode": "1.65.0",
Expand Down
Loading

0 comments on commit 23ecbe3

Please sign in to comment.