Skip to content

Commit

Permalink
Merge pull request #37 from gruppe-adler/fix-for-nodebb-1.15
Browse files Browse the repository at this point in the history
fix: get user from /user/:name instead of /me
  • Loading branch information
Fusselwurm authored Oct 27, 2022
2 parents 8cfc0dd + b50becb commit c37990f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/app/slotting/slotting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { environment } from '../../environments/environment';
import { HttpClient } from '@angular/common/http';
import * as io from 'socket.io-client';

interface User {
uid: string
}

@Injectable()
export class SlottingService implements OnDestroy {
public matches: any[];
Expand Down Expand Up @@ -239,15 +243,25 @@ export class SlottingService implements OnDestroy {
}
}

private async getFromApi(uri: string): Promise<any> {
return (await this.http.get(environment.api.forumUrl + '/api' + uri, {withCredentials: true}).toPromise());
}

public async getOwnUserId(): Promise<string> {
try {
const result = await this.http.get(environment.api.forumUrl + '/api/me', {withCredentials: true}).toPromise();
if (result['uid']) {
return result['uid'];
}
if (typeof result === 'string') { // expecting another api uri where the actual user data sits behind
const user = await this.getFromApi(result) as User;

return user.uid;
}
console.warn('unexpected return value from user API : ', result);
return '';
} catch (e) {
console.log(e);
console.error(e);
return '';
}
}
Expand Down

0 comments on commit c37990f

Please sign in to comment.