mirror of
https://github.com/datahub-project/datahub.git
synced 2025-07-15 21:24:15 +00:00
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { ApiStatus } from 'wherehows-web/utils/api/shared';
|
|
import { Response, faker } from 'ember-cli-mirage';
|
|
|
|
type StringOrNullOrUndefined = string | null | void;
|
|
|
|
const textContentHeader = { 'Content-Type': 'text/plain; charset=utf-8' };
|
|
|
|
/**
|
|
* Returns a config object for the config endpoint
|
|
* @param {object} _schema the auth table / factory object
|
|
* @param {requestBody} property on the request object passed in to mirage function handlers
|
|
* @return {{status: ApiStatus, data: object}}
|
|
*/
|
|
const getAuth = (_schema: {}, { requestBody }: { requestBody: string }) => {
|
|
const { username, password } = <{ username: StringOrNullOrUndefined; password: StringOrNullOrUndefined }>JSON.parse(
|
|
requestBody
|
|
);
|
|
|
|
if (!password) {
|
|
return new Response(400, textContentHeader, 'Missing or invalid [credentials]');
|
|
}
|
|
|
|
if (password === 'invalidPassword') {
|
|
return new Response(401, textContentHeader, 'Invalid Password');
|
|
}
|
|
|
|
return {
|
|
status: ApiStatus.OK,
|
|
data: { username, uuid: faker.random.uuid() }
|
|
};
|
|
};
|
|
|
|
export { getAuth };
|