Skip to content

Commit

Permalink
Merge pull request #523 from curveball/fix-app-auto-signup-flow
Browse files Browse the repository at this point in the history
Fix bug in 'App creation wizard' flow.
  • Loading branch information
evert authored Aug 26, 2024
2 parents 71ec152 + 024e686 commit 8551988
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
* Allow admins to auto-generate an intitial 'diceware' password when creating
new users, which should make onboaring new users and testing easier.
* Fix CSRF error on register form
* Fix a bug in the automatic App creation flow


0.26.1 (2024-08-12)
Expand Down
2 changes: 1 addition & 1 deletion src/app-client/formats/siren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function newClient(user: App, query: NewClientQuery ) {
name: 'requirePkce',
title: 'Require PKCE support (modern clients support this, but not everyone does)',
type: 'checkbox',
value: query.requirePkce === 'true'
value: !!query.requirePkce
},
],
}
Expand Down
12 changes: 9 additions & 3 deletions src/app/controller/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Controller from '@curveball/controller';
import { Context } from '@curveball/core';
import { createAppForm } from '../formats/html.js';
import * as services from '../../services.js';
import { Conflict, UnprocessableContent } from '@curveball/http-errors';
import { Conflict, NotFound, UnprocessableContent } from '@curveball/http-errors';
import { AppNewFormBody } from '../../api-types.js';

class CreateAppController extends Controller {
Expand Down Expand Up @@ -38,9 +38,15 @@ class CreateAppController extends Controller {
if (!identity.match(/^https?:(.*)$/)) {
throw new UnprocessableContent('App url must be a http or https URI');
}
if (await services.principalIdentity.findByUri(identity)) {
throw new Conflict('A principal with this URI already exists');

try {
if (await services.principalIdentity.findByUri(identity)) {
throw new Conflict('A principal with this URI already exists');
}
} catch (err) {
if (!(err instanceof NotFound)) throw err;
}

}

const newApp = await principalService.save({
Expand Down

0 comments on commit 8551988

Please sign in to comment.