Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging in always redirects you to the homepage #1161

Open
marijnvdwerf opened this issue Mar 23, 2024 · 2 comments
Open

Logging in always redirects you to the homepage #1161

marijnvdwerf opened this issue Mar 23, 2024 · 2 comments

Comments

@marijnvdwerf
Copy link
Collaborator

To Reproduce

  1. Be logged-out
  2. Open a scratch page
  3. Press login

Expected behavior
You're on the same scratch page you were at, but logged in.

**Actual behavior
You get redirected to the front page.

Conversely, logging out behaves as expected; you stay at the page you're at.

@shubhankar-shandilya-india
Copy link
Contributor

I am willing to work on this issue.
Could you tell what the potential cause for this issue is and any recommended way to fix it?

@conorgolden1
Copy link
Contributor

conorgolden1 commented May 15, 2024

I am willing to work on this issue. Could you tell what the potential cause for this issue is and any recommended way to fix it?

github apps have a callback url the user is authorized to redirect the user back to the application. You can add custom redirect_uri's as query parameters at the end of the authorization request. The trick is, is that the redirect_uri has to use the callback url as the base url but you can extend it with another query parameter to redirect from http://decomp.me/login to wherever the user was perviously. Simply get the current url from wherever the user was when they selected the github login button and attach that as a an extended redirect_uri. Then when that gets passed to the login page parse the query_param and redirect the user back to where they were.

Here's what the current request url is (src/lib/oauth.ts):

const url = `https://github.com/login/oauth/authorize?client_id=${GITHUB_CLIENT_ID}&scope=${encodeURIComponent(scope)}`

Here's an example of how you can use the redirect_uri (google is just an example but you'd want to redirect to where the user previously was):

const url = `https://github.com/login/oauth/authorize?client_id=${GITHUB_CLIENT_ID}&scope=${encodeURIComponent(scope)}&redirect_uri=https://decome.me/login?redirect=https://google.com`

EDIT:
Here's some documentation on callback_url's

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants