Skip to content

Commit

Permalink
fix: fixed an issue where the application would get confused about th…
Browse files Browse the repository at this point in the history
…e session state if the user logs out globally via the forum's logout functionality
  • Loading branch information
spuxx1701 committed Oct 29, 2023
1 parent f589f9d commit ca1eaa4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/).

## [2.2.2] - 2023-10-29

### Fixed

- Fixed an issue where the application would get confused about the session state if the user logs out globally via the forum's logout functionality.

## [2.2.1] - 2023-10-27

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "potber-api",
"version": "2.2.1",
"version": "2.2.2",
"description": "A modern JSON API for forum.mods.de",
"author": "",
"private": true,
Expand Down
12 changes: 10 additions & 2 deletions src/http/http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class HttpService {
*/
async get(url: string, options?: RequestOptions) {
const { cookie, headers, decode } = { decode: false, ...options };
const response = await firstValueFrom(
const response = await firstValueFrom<{ data: ArrayBuffer | string }>(
this.httpService
.get(url, {
responseEncoding: decode ? 'binary' : undefined,
Expand All @@ -47,9 +47,17 @@ export class HttpService {
);
if (decode) {
const decoder = new TextDecoder('iso-8859-15');
const text = decoder.decode(response.data);
const text = decoder.decode(response.data as ArrayBuffer);
response.data = text;
}
// Sessions may get terminated in case a user uses forum's the global 'log out' function.
// We'll check for any signs that happened and return a 401 so the client can act accordingly.
if (
(response.data as string) ===
'<?xml version="1.0" encoding="utf-8" ?>\n<not-logged-in />'
)
throw appExceptions.unauthorized;

return response as { data: string; headers: Record<string, string> };
}

Expand Down
4 changes: 3 additions & 1 deletion src/utility/transformers/boolean-string.transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Transform } from 'class-transformer';
*/
export function TransformBooleanString(key: string) {
return Transform(({ obj }) => {
return obj[key].toLowerCase() === 'true';
if (typeof obj[key] === 'boolean') return obj[key];
else if (typeof obj[key] === 'undefined') return false;
else if (typeof obj[key] === 'string') obj[key].toLowerCase() === 'true';
});
}

0 comments on commit ca1eaa4

Please sign in to comment.