Skip to content

Commit

Permalink
Better loading state, preset auth0 config
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten committed Aug 25, 2024
1 parent 7609204 commit f02f48c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from "react";
import { useNavigate } from "react-router-dom";
import { DeveloperHint } from "../../components/DeveloperHint.js";
import { ErrorPage } from "../../components/ErrorPage.js";
import { Spinner } from "../../components/Spinner.js";
import { SyntaxHighlight } from "../../components/SyntaxHighlight.js";

export function CallbackHandler({
Expand Down Expand Up @@ -50,5 +51,9 @@ export function CallbackHandler({
);
}

return <p>Loading...</p>;
return (
<div className="grid h-full place-items-center">
<Spinner />
</div>
);
}
28 changes: 27 additions & 1 deletion packages/zudoku/src/lib/authentication/providers/auth0.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { Auth0AuthenticationConfig } from "../../../config/config.js";
import {
Auth0AuthenticationConfig,
OpenIDAuthenticationConfig,
} from "../../../config/config.js";
import { AuthenticationProviderInitializer } from "../authentication.js";
import { useAuthState } from "../state.js";
import { OpenIDAuthenticationProvider } from "./openid.js";

class Auth0AuthenticationProvider extends OpenIDAuthenticationProvider {
constructor(config: OpenIDAuthenticationConfig) {
super(config);

// Prefill the authorization server since we know what Auth0's config is
this.authorizationServer = {
issuer: config.issuer,
authorization_endpoint: `${config.issuer}/authorize`,
token_endpoint: `${config.issuer}/oauth/token`,
code_challenge_methods_supported: ["S256", "plain"],
};
}

onAuthorizationUrl = async (
url: URL,
{ isSignUp }: { isSignUp: boolean },
Expand All @@ -12,6 +27,17 @@ class Auth0AuthenticationProvider extends OpenIDAuthenticationProvider {
url.searchParams.set("screen_hint", "signup");
}
};

override async getAuthServer() {
this.authorizationServer = {
issuer: new URL(this.authorizationEndpoint!).origin,
authorization_endpoint: this.authorizationEndpoint,
token_endpoint: this.tokenEndpoint,
code_challenge_methods_supported: [],
};
return this.authorizationServer;
}

signOut = async (): Promise<void> => {
useAuthState.setState({
isAuthenticated: false,
Expand Down

0 comments on commit f02f48c

Please sign in to comment.