Skip to content

Commit

Permalink
fix: hack to let us force refresh token (auto refresh logic is broke)
Browse files Browse the repository at this point in the history
  • Loading branch information
datagutt committed Aug 29, 2024
1 parent 33534ed commit 9479c05
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions example.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Kanpla from './src/kanpla';
import {Kanpla} from './src/kanpla';
import dotenv from 'dotenv';
dotenv.config();
const kanpla = new Kanpla({
Expand All @@ -14,7 +14,7 @@ async function main() {
const allMenus = await kanpla.getAllMenus();
/// console.log(`All menus:`, allMenus)

const menu = await kanpla.getMenusForToday();
const menu = await kanpla.getMenusForDate(new Date('2024-08-21'));
console.log(`Today's menu:`, menu);
}

Expand Down
6 changes: 5 additions & 1 deletion src/api-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ApiWrapperOptions = {
API_BASE_URL?: string;
};

export default class ApiWrapper {
export class ApiWrapper {
private firebaseAuthenticator: FirebaseAuthenticator;
private API_BASE_URL: string;
private instance = setupCache(
Expand All @@ -37,6 +37,10 @@ export default class ApiWrapper {
return await this.firebaseAuthenticator.getPortalToken();
}

async getTokenDirectly(): Promise<string> {
return await this.firebaseAuthenticator.getTokenDirectly(true);
}

getUserId(): string {
return this.firebaseAuthenticator.getLocalId();
}
Expand Down
4 changes: 2 additions & 2 deletions src/firebase-authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export default class FirebaseAuthenticator {
};
}

isDateInThePast(date: Date) {
isDateInThePast(date: Date): boolean {
const today = new Date();
return date.getTime() < today.getTime();
}

async login() {
async login(): Promise<void> {
const loginData = {
returnSecureToken: true,
email: this.credentials.email,
Expand Down
8 changes: 6 additions & 2 deletions src/kanpla.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ApiWrapper from './api-wrapper.js';
import {ApiWrapper} from './api-wrapper.js';
import {findDateInArray} from './utils.js';

type KanplaOptions = {
Expand All @@ -25,7 +25,7 @@ type MenuData = {
};
};

export default class Kanpla {
export class Kanpla {
private apiWrapper: ApiWrapper;
private options: KanplaOptions;
constructor(options: KanplaOptions) {
Expand All @@ -42,6 +42,10 @@ export default class Kanpla {
};
}

async forceRefreshToken(): Promise<boolean> {
return Boolean(await this.apiWrapper.getTokenDirectly())
}

async getFrontend() {

Check warning on line 49 in src/kanpla.ts

View workflow job for this annotation

GitHub Actions / build

Missing return type on function

Check warning on line 49 in src/kanpla.ts

View workflow job for this annotation

GitHub Actions / build

Missing return type on function
const userId = this.apiWrapper.getUserId();
const {data} = await this.apiWrapper.makeApiCall({
Expand Down

0 comments on commit 9479c05

Please sign in to comment.