Skip to content

Commit

Permalink
Logging to debug prod
Browse files Browse the repository at this point in the history
  • Loading branch information
Dropheart committed Sep 21, 2024
1 parent 37ada3e commit 764edfb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hono/auth/MsApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { buildUrl } from 'build-url-ts';
import { apiLogger } from '../logger';

type Secrets = {
tenantId: string;
Expand Down Expand Up @@ -37,6 +38,8 @@ export class MsAuthClient {
this.statesTail = (this.statesTail + 1) % this.maxStates;
this.states[this.statesTail] = _state;

console.log(`New state added: ${_state}\nCurrent tail: ${this.statesTail}\nStates: ${this.states}`);

const url = buildUrl(this.msAuthEndpoint, {
path: '/authorize',
queryParams: {
Expand All @@ -55,10 +58,12 @@ export class MsAuthClient {

public async verifyAndConsumeCode(code: string, state: string) {
const index = this.states.indexOf(state);
console.log(`State ${state} at index ${index}\nState array: ${this.states}\nstates[index] = ${this.states[index]}`)
if (index == -1) {
throw new Error(`Failed to verify code: Mismatched state.`);
}
this.states[index] = undefined;
console.log(`Removed state ${state} at index ${index}\nState array: ${this.states}\nstates[index] = ${this.states[index]}`)

const req = await fetch(`${this.msAuthEndpoint}/token`, {
method: 'POST',
Expand Down

0 comments on commit 764edfb

Please sign in to comment.