zudoku 0.3.0-dev.69 → 0.3.0-dev.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zudoku",
3
- "version": "0.3.0-dev.69",
3
+ "version": "0.3.0-dev.70",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -5,7 +5,7 @@ import { OAuthAuthorizationError } from "./errors.js";
5
5
  export function Callback({
6
6
  handleCallback,
7
7
  }: {
8
- handleCallback: () => Promise<void>;
8
+ handleCallback: () => Promise<string>;
9
9
  }) {
10
10
  const didInitialize = useRef(false);
11
11
  const [error, setError] = useState<Error | undefined>(undefined);
@@ -20,9 +20,9 @@ export function Callback({
20
20
  }
21
21
  didInitialize.current = true;
22
22
  handleCallback()
23
- .then(() => {
23
+ .then((redirect) => {
24
24
  // TODO: Handle return url, state, etc
25
- navigate("/");
25
+ navigate(redirect);
26
26
  })
27
27
  .catch((err) => {
28
28
  setError(err);
@@ -44,12 +44,11 @@ class Auth0AuthenticationProvider extends OpenIDAuthenticationProvider {
44
44
 
45
45
  const auth0Auth: AuthenticationProviderInitializer<
46
46
  Auth0AuthenticationConfig
47
- > = ({ domain, clientId, audience }) =>
47
+ > = ({ domain, ...options }) =>
48
48
  new Auth0AuthenticationProvider({
49
+ ...options,
49
50
  type: "openid",
50
51
  issuer: `https://${domain}`,
51
- clientId: clientId,
52
- audience: audience,
53
52
  });
54
53
 
55
54
  export default auth0Auth;
@@ -22,7 +22,7 @@ interface TokenState {
22
22
  class OpenIdAuthPlugin extends AuthenticationPlugin {
23
23
  constructor(
24
24
  private callbackUrlPath: string,
25
- private handleCallback: () => Promise<void>,
25
+ private handleCallback: () => Promise<string>,
26
26
  ) {
27
27
  super();
28
28
  }
@@ -48,9 +48,9 @@ export class OpenIDAuthenticationProvider implements AuthenticationProvider {
48
48
 
49
49
  protected callbackUrlPath = "/oauth/callback";
50
50
  protected logoutRedirectUrlPath = "/";
51
- private redirectToAfterSignUp?: string;
52
- private redirectToAfterSignIn?: string;
53
- private redirectToAfterSignOut?: string;
51
+ private redirectToAfterSignUp: string;
52
+ private redirectToAfterSignIn: string;
53
+ private redirectToAfterSignOut: string;
54
54
 
55
55
  constructor({
56
56
  issuer,
@@ -129,6 +129,11 @@ export class OpenIDAuthenticationProvider implements AuthenticationProvider {
129
129
  private async authorize(signUp = false): Promise<void> {
130
130
  const code_challenge_method = "S256";
131
131
  const authorizationServer = await this.getAuthServer();
132
+ if (signUp) {
133
+ localStorage.setItem("sign-up", "true");
134
+ } else {
135
+ localStorage.removeItem("sign-up");
136
+ }
132
137
 
133
138
  if (!authorizationServer.authorization_endpoint) {
134
139
  throw new AuthorizationError("No authorization endpoint");
@@ -250,7 +255,7 @@ export class OpenIDAuthenticationProvider implements AuthenticationProvider {
250
255
  }
251
256
  }
252
257
 
253
- handleCallback = async (): Promise<void> => {
258
+ handleCallback = async (): Promise<string> => {
254
259
  const url = new URL(window.location.href);
255
260
  const state = url.searchParams.get("state");
256
261
 
@@ -282,7 +287,7 @@ export class OpenIDAuthenticationProvider implements AuthenticationProvider {
282
287
  }
283
288
 
284
289
  const redirectUrl = new URL(url);
285
- redirectUrl.pathname = this.callbackUrlPath;
290
+ redirectUrl.pathname = this.redirectToAfterSignIn ?? this.callbackUrlPath;
286
291
  redirectUrl.search = "";
287
292
 
288
293
  const response = await oauth.authorizationCodeGrantRequest(
@@ -332,6 +337,12 @@ export class OpenIDAuthenticationProvider implements AuthenticationProvider {
332
337
  profile,
333
338
  });
334
339
 
340
+ if (localStorage.getItem("sign-up")) {
341
+ return this.redirectToAfterSignUp;
342
+ } else {
343
+ return this.redirectToAfterSignIn;
344
+ }
345
+
335
346
  // // Remove the query strings so react query doesn't keep retrying
336
347
  // // to make the token request
337
348
  // history.replaceState({}, "", window.location.pathname);