-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
791 additions
and
732 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Request } from 'express' | ||
import * as Helper from './Helper' | ||
import * as env from '../config/env.config' | ||
|
||
/** | ||
* Check whether the request is from the backend or not. | ||
* | ||
* @export | ||
* @param {Request} req | ||
* @returns {boolean} | ||
*/ | ||
export const isBackend = (req: Request): boolean => !!req.headers.origin && Helper.trim(req.headers.origin, '/') === Helper.trim(env.BACKEND_HOST, '/') | ||
|
||
/** | ||
* Check whether the request is from the frontend or not. | ||
* | ||
* @export | ||
* @param {Request} req | ||
* @returns {boolean} | ||
*/ | ||
export const isFrontend = (req: Request): boolean => !!req.headers.origin && Helper.trim(req.headers.origin, '/') === Helper.trim(env.FRONTEND_HOST, '/') | ||
|
||
/** | ||
* Get authentification cookie name. | ||
* | ||
* @param {Request} req | ||
* @returns {string} | ||
*/ | ||
export const getAuthCookieName = (req: Request): string => { | ||
if (isBackend(req)) { | ||
// Backend auth cookie name | ||
return env.BACKEND_AUTH_COOKIE_NAME | ||
} | ||
|
||
if (isFrontend(req)) { | ||
// Frontend auth cookie name | ||
return env.FRONTEND_AUTH_COOKIE_NAME | ||
} | ||
|
||
// Mobile app and unit tests auth header name | ||
return env.X_ACCESS_TOKEN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.