Skip to content

Commit

Permalink
fix: adding debug points
Browse files Browse the repository at this point in the history
  • Loading branch information
meza committed Jul 8, 2023
1 parent 49a6c3c commit 169668a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class Auth0RemixServer {
private readonly credentialsCallback: Auth0CredentialsCallback;

constructor(auth0RemixOptions: Auth0RemixOptions) {
console.error('This is working ffs debug 0');
this.domain = ensureDomain(auth0RemixOptions.clientDetails.domain);

/**
Expand Down Expand Up @@ -239,15 +240,18 @@ export class Auth0RemixServer {

public async getUser(request: Request, context: AppLoadContext): Promise<UserProfile> {
let credentials: UserCredentials;

console.log('debug 1');
try {
console.log('debug 2');
credentials = await getCredentials(request, this.session);
} catch (err) {
console.log('debug 3');
console.error('No credentials found');
throw redirect(this.failedLoginRedirect + '?error=no_credentials');
}

try {
console.log('debug 4');
await this.decodeToken(credentials.accessToken, Token.ACCESS);

return await this.getUserProfile(credentials);
Expand Down Expand Up @@ -283,6 +287,8 @@ export class Auth0RemixServer {
body.set('client_secret', this.clientCredentials.clientSecret);
body.set('refresh_token', credentials.refreshToken);

console.log('Refreshing token', credentials);

const response = await fetch(this.auth0Urls.tokenURL, {
headers: { 'content-type': 'application/x-www-form-urlencoded' },
method: 'POST',
Expand Down Expand Up @@ -313,14 +319,15 @@ export class Auth0RemixServer {
}

private async getUserProfile(credentials: UserCredentials): Promise<UserProfile> {
console.log('debug 5');
const response = await fetch(this.auth0Urls.userProfileUrl, {
headers: {
Authorization: `Bearer ${credentials.accessToken}`
}
});

const searchParams = new URLSearchParams();

console.log('debug 6');
if (!response.ok) {
console.error('Failed to get user profile from Auth0');
searchParams.set('error', await this.getErrorReason(response));
Expand Down

0 comments on commit 169668a

Please sign in to comment.