@@ -1,7 +1,7 @@
|
|||||||
import { Role } from "@probo/helpers";
|
import { Role } from "@probo/helpers";
|
||||||
import { lazy } from "@probo/react-lazy";
|
import { lazy } from "@probo/react-lazy";
|
||||||
import {
|
import {
|
||||||
NotAssumingError,
|
AssumptionRequiredError,
|
||||||
UnAuthenticatedError,
|
UnAuthenticatedError,
|
||||||
} from "@probo/relay";
|
} from "@probo/relay";
|
||||||
import { type AppRoute, routeFromAppRoute } from "@probo/routes";
|
import { type AppRoute, routeFromAppRoute } from "@probo/routes";
|
||||||
@@ -48,7 +48,7 @@ function ErrorBoundary() {
|
|||||||
return <Navigate to="/auth/login" />;
|
return <Navigate to="/auth/login" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error instanceof NotAssumingError) {
|
if (error instanceof AssumptionRequiredError) {
|
||||||
// TODO redirect to right URL
|
// TODO redirect to right URL
|
||||||
return <Navigate to="/" />;
|
return <Navigate to="/" />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ export class InternalServerError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NotAssumingError extends Error {
|
export class AssumptionRequiredError extends Error {
|
||||||
constructor(message?: string) {
|
constructor(message?: string) {
|
||||||
super(message ?? "NOT_ASSUMING");
|
super(message ?? "ASSUMPTION_REQUIRED");
|
||||||
this.name = "NotAssumingError";
|
this.name = "AssumptionRequiredError";
|
||||||
Object.setPrototypeOf(this, NotAssumingError.prototype)
|
Object.setPrototypeOf(this, AssumptionRequiredError.prototype)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ import {
|
|||||||
UnAuthenticatedError,
|
UnAuthenticatedError,
|
||||||
UnauthorizedError,
|
UnauthorizedError,
|
||||||
ForbiddenError,
|
ForbiddenError,
|
||||||
NotAssumingError,
|
AssumptionRequiredError,
|
||||||
} from "./errors";
|
} from "./errors";
|
||||||
import { GraphQLError } from "graphql";
|
import { GraphQLError } from "graphql";
|
||||||
|
|
||||||
const hasUnauthenticatedError = (error: GraphQLError) =>
|
const hasUnauthenticatedError = (error: GraphQLError) =>
|
||||||
error.extensions?.code == "UNAUTHENTICATED";
|
error.extensions?.code == "UNAUTHENTICATED";
|
||||||
|
|
||||||
const hasNotAssumingError = (error: GraphQLError) =>
|
const hasAssumptionRequiredError = (error: GraphQLError) =>
|
||||||
error.extensions?.code == "NOT_ASSUMING";
|
error.extensions?.code == "ASSUMPTION_REQUIRED";
|
||||||
|
|
||||||
const hasUnauthorizedError = (error: GraphQLError) =>
|
const hasUnauthorizedError = (error: GraphQLError) =>
|
||||||
error.extensions?.code == "UNAUTHORIZED";
|
error.extensions?.code == "UNAUTHORIZED";
|
||||||
@@ -83,9 +83,9 @@ export const makeFetchQuery = (endpoint: string): FetchFunction => {
|
|||||||
throw new UnAuthenticatedError(unauthenticatedError.message);
|
throw new UnAuthenticatedError(unauthenticatedError.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const notAssumingError = errors.find(hasNotAssumingError);
|
const assumptionRequiredError = errors.find(hasAssumptionRequiredError);
|
||||||
if (notAssumingError) {
|
if (assumptionRequiredError) {
|
||||||
throw new NotAssumingError(notAssumingError.message)
|
throw new AssumptionRequiredError(assumptionRequiredError.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
const unauthorizedError = errors.find(hasUnauthorizedError);
|
const unauthorizedError = errors.find(hasUnauthorizedError);
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ func (a *Authorizer) authorize(ctx context.Context, conn pg.Conn, params Authori
|
|||||||
var errSessionExpired *ErrSessionExpired
|
var errSessionExpired *ErrSessionExpired
|
||||||
|
|
||||||
if errors.As(err, &errSessionNotFound) || errors.As(err, &errSessionExpired) {
|
if errors.As(err, &errSessionNotFound) || errors.As(err, &errSessionExpired) {
|
||||||
return NewAssumptionNeededError(params.Principal, membership.ID)
|
return NewAssumptionRequiredError(params.Principal, membership.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("cannot get active child session for membership: %w", err)
|
return fmt.Errorf("cannot get active child session for membership: %w", err)
|
||||||
|
|||||||
@@ -183,17 +183,17 @@ func (e ErrInsufficientPermissions) Error() string {
|
|||||||
return fmt.Sprintf("identity %q does not have sufficient permissions to perform action %s on entity %q", e.IdentityID, e.Action, e.EntityID)
|
return fmt.Sprintf("identity %q does not have sufficient permissions to perform action %s on entity %q", e.IdentityID, e.Action, e.EntityID)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrAssumptionNeeded struct {
|
type ErrAssumptionRequired struct {
|
||||||
IdentityID gid.GID
|
IdentityID gid.GID
|
||||||
MembershipID gid.GID
|
MembershipID gid.GID
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAssumptionNeededError(identityID gid.GID, membershipID gid.GID) error {
|
func NewAssumptionRequiredError(identityID gid.GID, membershipID gid.GID) error {
|
||||||
return &ErrAssumptionNeeded{IdentityID: identityID, MembershipID: membershipID}
|
return &ErrAssumptionRequired{IdentityID: identityID, MembershipID: membershipID}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrAssumptionNeeded) Error() string {
|
func (e ErrAssumptionRequired) Error() string {
|
||||||
return fmt.Sprintf("assumption for identity %q needed for membership %q", e.IdentityID, e.MembershipID)
|
return fmt.Sprintf("assumption for identity %q required for membership %q", e.IdentityID, e.MembershipID)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrSessionNotFound struct{ SessionID gid.GID }
|
type ErrSessionNotFound struct{ SessionID gid.GID }
|
||||||
|
|||||||
@@ -72,9 +72,9 @@ func NewAuthorizeFunc(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := svc.Authorizer.Authorize(ctx, params); err != nil {
|
if err := svc.Authorizer.Authorize(ctx, params); err != nil {
|
||||||
var errAssumptionNeeded *iam.ErrAssumptionNeeded
|
var errAssumptionRequired *iam.ErrAssumptionRequired
|
||||||
if errors.As(err, &errAssumptionNeeded) {
|
if errors.As(err, &errAssumptionRequired) {
|
||||||
return gqlutils.NotAssuming(ctx, err)
|
return gqlutils.AssumptionRequired(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var errInsufficientPermissions *iam.ErrInsufficientPermissions
|
var errInsufficientPermissions *iam.ErrInsufficientPermissions
|
||||||
|
|||||||
@@ -52,18 +52,18 @@ func Unauthenticatedf(ctx context.Context, format string, a ...any) *gqlerror.Er
|
|||||||
return Unauthenticated(ctx, fmt.Errorf(format, a...))
|
return Unauthenticated(ctx, fmt.Errorf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func NotAssuming(ctx context.Context, err error) *gqlerror.Error {
|
func AssumptionRequired(ctx context.Context, err error) *gqlerror.Error {
|
||||||
return &gqlerror.Error{
|
return &gqlerror.Error{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
Path: graphql.GetPath(ctx),
|
Path: graphql.GetPath(ctx),
|
||||||
Extensions: map[string]any{
|
Extensions: map[string]any{
|
||||||
"code": "NOT_ASSUMING",
|
"code": "ASSUMPTION_REQUIRED",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NotAssumingf(ctx context.Context, format string, a ...any) *gqlerror.Error {
|
func AssumptionRequiredf(ctx context.Context, format string, a ...any) *gqlerror.Error {
|
||||||
return NotAssuming(ctx, fmt.Errorf(format, a...))
|
return AssumptionRequired(ctx, fmt.Errorf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func Forbidden(ctx context.Context, err error) *gqlerror.Error {
|
func Forbidden(ctx context.Context, err error) *gqlerror.Error {
|
||||||
|
|||||||
Reference in New Issue
Block a user