mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat: add /sign-in/abort
api, close #32
This commit is contained in:
parent
9befa9c5f6
commit
0356010ee3
2 changed files with 16 additions and 2 deletions
|
@ -4,15 +4,20 @@ export enum GuardErrorCode {
|
|||
InvalidInput = 'guard.invalid_input',
|
||||
}
|
||||
|
||||
export enum OidcErrorCode {
|
||||
Aborted = 'oidc.aborted',
|
||||
}
|
||||
|
||||
export enum RegisterErrorCode {
|
||||
UsernameExists = 'register.username_exists',
|
||||
}
|
||||
|
||||
export type RequestErrorCode = GuardErrorCode | RegisterErrorCode;
|
||||
export type RequestErrorCode = GuardErrorCode | OidcErrorCode | RegisterErrorCode;
|
||||
|
||||
const requestErrorMessage: Record<RequestErrorCode, string> = {
|
||||
[RegisterErrorCode.UsernameExists]: 'The username already exists.',
|
||||
[GuardErrorCode.InvalidInput]: 'The request input is invalid.',
|
||||
[OidcErrorCode.Aborted]: 'The end-user aborted interaction.',
|
||||
[RegisterErrorCode.UsernameExists]: 'The username already exists.',
|
||||
};
|
||||
|
||||
export type RequestErrorMetadata = {
|
||||
|
|
|
@ -6,6 +6,7 @@ import { findUserById } from '@/queries/user';
|
|||
import { Provider } from 'oidc-provider';
|
||||
import { conditional } from '@logto/essentials';
|
||||
import koaGuard from '@/middleware/koa-guard';
|
||||
import { OidcErrorCode } from '@/errors/RequestError';
|
||||
|
||||
export default function createSignInRoutes(provider: Provider) {
|
||||
const router = new Router();
|
||||
|
@ -82,5 +83,13 @@ export default function createSignInRoutes(provider: Provider) {
|
|||
ctx.body = { redirectTo };
|
||||
});
|
||||
|
||||
router.post('/sign-in/abort', async (ctx) => {
|
||||
await provider.interactionDetails(ctx.req, ctx.res);
|
||||
const redirectTo = await provider.interactionResult(ctx.req, ctx.res, {
|
||||
error: OidcErrorCode.Aborted,
|
||||
});
|
||||
ctx.body = { redirectTo };
|
||||
});
|
||||
|
||||
return router.routes();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue