Skip to content

Commit

Permalink
Merge pull request #1141 from FoalTS/reorganize-utils-jwt-sessions
Browse files Browse the repository at this point in the history
Reorganize utils in `jwt/` and `sessions/`
  • Loading branch information
LoicPoullain authored Aug 19, 2022
2 parents f970d92 + c0f1e16 commit 3092ac1
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 19 deletions.
5 changes: 1 addition & 4 deletions packages/core/src/sessions/http/use-sessions.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ import {
import { SESSION_DEFAULT_COOKIE_NAME } from './constants';
import { createSession, readSession, SessionStore } from '../core';
import { FetchUser } from './fetch-user.interface';
import { removeSessionCookie } from './remove-session-cookie';
import { setSessionCookie } from './set-session-cookie';
import { getCsrfTokenFromRequest } from './get-csrf-token-from-request';
import { shouldVerifyCsrfToken } from './utils';
import { getCsrfTokenFromRequest, removeSessionCookie, setSessionCookie, shouldVerifyCsrfToken } from './utils';

export interface UseSessionOptions {
user?: FetchUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { strictEqual } from 'assert';

// FoalTS
import { Context } from '../../core';
import { Context } from '../../../core';
import { getCsrfTokenFromRequest } from './get-csrf-token-from-request';

function createRequest(body: { [name: string]: any }, headers: { [name: string ]: string}): Context['request'] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context } from '../../core';
import { Context } from '../../../core';

export function getCsrfTokenFromRequest(request: Context['request']): string|undefined {
return request.body._csrf || request.get('X-CSRF-Token') || request.get('X-XSRF-Token');
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/sessions/http/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { shouldVerifyCsrfToken } from './should-verify-csrf-token';
export { getCsrfTokenFromRequest } from './get-csrf-token-from-request';
export { shouldVerifyCsrfToken } from './should-verify-csrf-token';
export { removeSessionCookie } from './remove-session-cookie';
export { setSessionCookie } from './set-session-cookie';
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import { strictEqual } from 'assert';

// FoalTS
import { Config, HttpResponse, HttpResponseOK } from '../../core';
import { Config, HttpResponse, HttpResponseOK } from '../../../core';
import {
SESSION_DEFAULT_COOKIE_HTTP_ONLY,
SESSION_DEFAULT_COOKIE_NAME,
SESSION_DEFAULT_COOKIE_PATH,
SESSION_DEFAULT_CSRF_COOKIE_NAME,
SESSION_DEFAULT_SAME_SITE_ON_CSRF_ENABLED,
SESSION_USER_COOKIE_NAME,
} from './constants';
} from '../constants';
import { removeSessionCookie } from './remove-session-cookie';

describe('removeSessionCookie', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// FoalTS
import { Config, CookieOptions, HttpResponse } from '../../core';
import { Config, CookieOptions, HttpResponse } from '../../../core';
import {
SESSION_DEFAULT_COOKIE_HTTP_ONLY,
SESSION_DEFAULT_COOKIE_NAME,
SESSION_DEFAULT_COOKIE_PATH,
SESSION_DEFAULT_CSRF_COOKIE_NAME,
SESSION_DEFAULT_SAME_SITE_ON_CSRF_ENABLED,
SESSION_USER_COOKIE_NAME,
} from './constants';
} from '../constants';

/**
* Deletes the browser cookie containing the session token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
import { deepStrictEqual, strictEqual } from 'assert';

// FoalTS
import { Config, HttpResponse, HttpResponseOK } from '../../core';
import { Config, HttpResponse, HttpResponseOK } from '../../../core';
import {
SESSION_DEFAULT_COOKIE_HTTP_ONLY,
SESSION_DEFAULT_COOKIE_NAME,
SESSION_DEFAULT_COOKIE_PATH,
SESSION_DEFAULT_CSRF_COOKIE_NAME,
SESSION_DEFAULT_SAME_SITE_ON_CSRF_ENABLED,
SESSION_USER_COOKIE_NAME,
} from './constants';
import { Session } from '../core';
} from '../constants';
import { Session } from '../../core';
import { setSessionCookie } from './set-session-cookie';

describe('setSessionCookie', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// FoalTS
import { Config, CookieOptions, HttpResponse } from '../../core';
import { Config, CookieOptions, HttpResponse } from '../../../core';
import {
SESSION_DEFAULT_COOKIE_HTTP_ONLY,
SESSION_DEFAULT_COOKIE_NAME,
SESSION_DEFAULT_COOKIE_PATH,
SESSION_DEFAULT_CSRF_COOKIE_NAME,
SESSION_DEFAULT_SAME_SITE_ON_CSRF_ENABLED,
SESSION_USER_COOKIE_NAME,
} from './constants';
import { Session } from '../core';
} from '../constants';
import { Session } from '../../core';

/**
* Sends the session token in a cookie.
Expand Down
3 changes: 1 addition & 2 deletions packages/jwt/src/http/jwt.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import { decode, verify } from 'jsonwebtoken';
// FoalTS
import { JWT_DEFAULT_COOKIE_NAME, JWT_DEFAULT_CSRF_COOKIE_NAME } from './constants';
import { getSecretOrPublicKey } from '../core';
import { getCsrfTokenFromRequest } from './get-csrf-token-from-request';
import { isInvalidTokenError } from './invalid-token.error';
import { getCsrfTokenFromCookie, shouldVerifyCsrfToken } from './utils';
import { getCsrfTokenFromCookie, getCsrfTokenFromRequest, shouldVerifyCsrfToken } from './utils';

class InvalidTokenResponse extends HttpResponseUnauthorized {

Expand Down
1 change: 1 addition & 0 deletions packages/jwt/src/http/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { getCsrfTokenFromCookie } from './get-csrf-token-from-cookie';
export { getCsrfTokenFromRequest } from './get-csrf-token-from-request';
export { shouldVerifyCsrfToken } from './should-verify-csrf-token';

0 comments on commit 3092ac1

Please sign in to comment.