Skip to content

Conversation

ChristopherChudzicki
Copy link
Contributor

@ChristopherChudzicki ChristopherChudzicki commented Oct 16, 2025

What are the relevant tickets?

Closes

Description (What does it do?)

On login, redirect users to dashboard home in most cases. Exception: if they were trying to access a specific page (Signup/login popover, or auth redirect).

How can this be tested?

Prerequisite for #5 only: MITxOnline integration with organizations set up.

Start as an anonymous user in each scenario below.

  1. From any page, click login button in header.
    • New account: You should be redirected to onboarding, then to dashboard home.
    • Existing account: You should be redirected to dashboard home
  2. From homepage, "personalize section" (blue background), click "Sign up for free":
    • New Account: you should go to dashboard home
    • Existing Account: you should go to dashboard home
  3. Visit http://learn.odl.local/dashboard/my-lists directly in your browser URL bar (Or any auth-requiring page, but that is an example w/o any special permission requirements; A more realistic example would be http://learn.odl.local/dashboard/my-organization)
    • New Account: You should go to onboarding, then be directed to original page you started on (e.g., my-lists)
    • Existing Account: You be redirected to original page you started on (e.g., my-lists)
  4. From any page, trigger the "signup/login popover". (E.g., in resource drawer, by clicking "Bookmark course"). Click the signup button.
    • New Account: Back to the original page (e.g., resource drawer) after login
    • Existing Account: Back to the original page (e.g., resource drawer)
  5. Get an enrollment code for your mitxonline organization and visit /enrollmentcode/{enrollmentcode} page.
    • New Account: You should be redirected to dashboard home and skip onboarding
      • ⚠️ I often get 500 errors from local keycloak in this scenario for so-far-unexplained-reasons. In network tab of dev console, you can check that the enrollmentcode page redirected you to a page like http://api.learn.odl.local:8065/login?next=http://learn.odl.local:8062/enrollmentcode/ENROLLMENT_CODE_VALUE prior to redirecting you to keycloak. If I visit http://api.learn.odl.local:8065/login?next=http://learn.odl.local:8062/enrollmentcode/ENROLLMENT_CODE_VALUE directly, I tend not to get the 500 error.
    • Existing Account: You should be redirected to dashboard home (NOT the org page)
  6. Users associated with keycloak organizations before logging into learn should also be redirected to dashboard on first signup, skipping onboarding.

Additional Context

With the new simplified behavior, the signup_next parameter is unused. I've mostly removed it from the frontend code, but left it on the backend in case we need it.

@ChristopherChudzicki ChristopherChudzicki force-pushed the cc/simplify-login-redirects branch from 7e8d1cf to 5c373f2 Compare October 16, 2025 19:30
@ChristopherChudzicki ChristopherChudzicki changed the title Cc/simplify login redirects Redirect to dashboard home after login, usually Oct 16, 2025
Comment on lines -175 to -180
* To include search parameters in the next URL, we need to encode them.
* If we pass `?next=/foo/bar?cat=meow` directly, Django receives two separate
* parameters: `next` and `cat`.
*
* There's no need to encode the path parameter (it might contain slashes,
* but those are allowed in search parameters) so let's keep it readable.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to encode the path parameter (it might contain slashes, but those are allowed in search parameters) so let's keep it readable.

It might also contain pluses, which are problematic.

Try logging into RC via login button at https://rc.learn.mit.edu/courses/course-v1:MITxT+8.01.1x/ to see the issue. (Once this PR is merged, that button will go to the dashboard, but it's still good to fix this. We will have the signup popover on the product pages, too.)

from django.utils.text import slugify
from django.views import View

from main import settings
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing from main instead of django.conf breaks the pytest django fixtures.

def test_custom_logout_view(mocker, client, user, is_authenticated, has_next):
def test_custom_logout_view(mocker, client, user, is_authenticated, has_next, settings): # noqa: PLR0913
"""Test logout redirect"""
settings.ALLOWED_REDIRECT_HOSTS = ["ocw.mit.edu"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was broken for me locally because I guess my local env file overrides this value.

Copy link
Contributor

@jonkafton jonkafton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

loginUrl.searchParams.set("skip_onboarding", "1")
router.push(loginUrl.toString())
}
}, [userLoading, user, code, router])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably no race condition if the attachisSuccess will never be true for unauthenticated users, but should we wait for !userLoading before calling attach to avoid the unnecessary call?

@ChristopherChudzicki ChristopherChudzicki force-pushed the cc/simplify-login-redirects branch from 8900933 to f1cbaa1 Compare October 20, 2025 18:38
@ChristopherChudzicki ChristopherChudzicki merged commit 2d8a2bf into main Oct 20, 2025
13 checks passed
@ChristopherChudzicki ChristopherChudzicki deleted the cc/simplify-login-redirects branch October 20, 2025 21:30
@odlbot odlbot mentioned this pull request Oct 21, 2025
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants