Fix customer login and credit-card checkout on non-Development environments#979
Open
hristobakalov wants to merge 1 commit into
Open
Conversation
…nments Register AddCmsAspNetIdentity<SiteUser> in all environments instead of Development only. The null ServiceAccessor stubs previously registered on non-Development caused NullReferenceExceptions on every customer login and made profile/order/address/checkout pages unresolvable from DI. Opti ID (AddOptimizelyIdentity, useAsDefault: false) only overrides authentication schemes for CMS UI paths, so it coexists with ASP.NET Identity for site visitors by design. The identity connection string now reuses the EcfSqlConnection -> EPiServerDB fallback so it also works on DXP. Remove the dead hard cast to the stubbed ICreditCardPayment in GenericCreditCardPaymentGateway. Commerce 15 removed the interface and the payment option now creates a generic IPayment, so the cast threw InvalidCastException and failed every credit-card purchase. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On deployed (non-Development) environments, logging in as any existing site user (e.g. the demo user David Knipe) failed with the generic error page "Something Went Wrong — Something went wrong when trying to access this resource." All account pages (profile, order history, addresses) and checkout were equally broken. Completing a purchase with a credit card failed even where login worked.
Root causes
1. ASP.NET Identity was not registered outside Development (
src/Foundation/Startup.cs)The upgrade only called
AddCmsAspNetIdentity<SiteUser>()in Development, on the assumption that Opti ID replaces it on DXP. On other environments it registered null-returning stubs:Consequences on deployed sites:
PublicApiController.Login/InternalLogincalledSignInManager().SignInAsync(...)on null →NullReferenceException→ 500 on every customer login.ProfilePageController,OrderHistoryController,ResetPasswordController,UsersControllerandCheckoutControllerconstructor-injectApplicationSignInManager<SiteUser>/ApplicationUserManager<SiteUser>directly — unresolvable from DI → 500 on profile, orders, addresses and checkout pages.The assumption was incorrect:
AddOptimizelyIdentity()(called withuseAsDefault: false) installs anIAuthenticationSchemeProviderdecorator that overrides authentication only for CMS UI paths (protected modules, edit/preview context) and delegates everything else to the app default. Opti ID (editors) and ASP.NET Identity (site visitors) are designed to coexist.Fix: register
AddCmsAspNetIdentity<SiteUser>unconditionally (as CMS 12 did), remove the null stubs, and use the existingEcfSqlConnection→EPiServerDBfallback so it also works on DXP where onlyEPiServerDBis injected. The Opti ID registration is unchanged.2. Credit-card purchases threw
InvalidCastException(GenericCreditCardPaymentGateway.cs)Commerce 15 removed
ICreditCardPayment; this branch replaced it with a compile-only stub inCommerceTypeStubs.csthat no runtime payment type implements, and changedGenericCreditCardPaymentOptionto create a genericIPayment. The gateway still hard-cast the payment:This made
cart.ProcessPayments(...)fail for the default demo payment method, so no credit-card order could ever be placed. The cast result was dead code (the card-number validation using it is commented out).Fix: removed the dead cast; the gateway returns its (already unconditional) successful result.
Not changed (known Commerce 15 preview gaps, flagged in code)
CreditCardService) remain stubbed out.OrderGroupWorkflowManagerremoved in Commerce 15).Verification
dotnet build -c Release— succeeds, 0 errors.🤖 Generated with Claude Code