decompme / decomp.me

Collaborative decompilation and reverse engineering website
https://decomp.me
MIT License
375 stars 117 forks source link

Logging in always redirects you to the homepage #1161

Open marijnvdwerf opened 6 months ago

marijnvdwerf commented 6 months ago

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 commented 4 months ago

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 commented 4 months ago

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