mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
feat(core): get /session/register/:username/existence
(#275)
* feat(core): add username existence check when resgitering * feat(core): add username existence check * feat(core): update username guard to avoid empty strings
This commit is contained in:
parent
75d2bb3e9b
commit
bd6dc4261c
2 changed files with 14 additions and 0 deletions
|
@ -36,6 +36,7 @@ import {
|
|||
findUserByIdentity,
|
||||
} from '@/queries/user';
|
||||
import assertThat from '@/utils/assert-that';
|
||||
import { usernameRegEx } from '@/utils/regex';
|
||||
|
||||
import { AnonymousRouter } from './types';
|
||||
|
||||
|
@ -308,6 +309,18 @@ export default function sessionRoutes<T extends AnonymousRouter>(router: T, prov
|
|||
}
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/session/register/:username/existence',
|
||||
koaGuard({ params: object({ username: string().regex(usernameRegEx) }) }),
|
||||
async (ctx, next) => {
|
||||
const { username } = ctx.guard.params;
|
||||
|
||||
ctx.body = { existence: await hasUser(username) };
|
||||
|
||||
return next();
|
||||
}
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/session/register/passwordless/phone/send-passcode',
|
||||
koaGuard({ body: object({ phone: string() }) }),
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
export const emailRegEx = /^\S+@\S+\.\S+$/;
|
||||
export const phoneRegEx = /^[1-9]\d{10}$/;
|
||||
export const usernameRegEx = /^[A-Za-z]\w*$/;
|
||||
|
|
Loading…
Reference in a new issue