2025-05-10 02:09:06 +02:00
|
|
|
/*!
|
|
|
|
|
* Copyright (c) 2024 PLANKA Software GmbH
|
|
|
|
|
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
|
|
|
|
*/
|
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
/**
|
|
|
|
|
* unauthorized.js
|
|
|
|
|
*
|
|
|
|
|
* A custom response.
|
|
|
|
|
*
|
|
|
|
|
* Example usage:
|
|
|
|
|
* ```
|
|
|
|
|
* return res.unauthorized();
|
|
|
|
|
* // -or-
|
|
|
|
|
* return res.unauthorized(optionalData);
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* Or with actions2:
|
|
|
|
|
* ```
|
|
|
|
|
* exits: {
|
|
|
|
|
* somethingHappened: {
|
|
|
|
|
* responseType: 'unauthorized'
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* ```
|
|
|
|
|
* throw 'somethingHappened';
|
|
|
|
|
* // -or-
|
|
|
|
|
* throw { somethingHappened: optionalData }
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
|
|
|
|
|
2025-09-08 16:20:27 +02:00
|
|
|
/**
|
|
|
|
|
* @swagger
|
|
|
|
|
* components:
|
|
|
|
|
* responses:
|
|
|
|
|
* Unauthorized:
|
|
|
|
|
* description: Authentication required or invalid credentials
|
|
|
|
|
* content:
|
|
|
|
|
* application/json:
|
|
|
|
|
* schema:
|
|
|
|
|
* type: object
|
|
|
|
|
* required:
|
|
|
|
|
* - code
|
|
|
|
|
* - message
|
|
|
|
|
* properties:
|
|
|
|
|
* code:
|
|
|
|
|
* type: string
|
|
|
|
|
* description: Error code
|
|
|
|
|
* example: E_UNAUTHORIZED
|
|
|
|
|
* message:
|
|
|
|
|
* type: string
|
|
|
|
|
* description: Error message
|
|
|
|
|
* example: Access token is missing, invalid or expired
|
|
|
|
|
*/
|
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
module.exports = function unauthorized(message) {
|
|
|
|
|
const { res } = this;
|
|
|
|
|
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: 'E_UNAUTHORIZED',
|
2019-11-05 18:01:42 +05:00
|
|
|
message,
|
2019-08-31 04:07:25 +05:00
|
|
|
});
|
|
|
|
|
};
|