Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Add Logout button #388

Merged
merged 14 commits into from
Nov 29, 2018
Merged

Add Logout button #388

merged 14 commits into from
Nov 29, 2018

Conversation

T4rk1n
Copy link
Contributor

@T4rk1n T4rk1n commented Nov 20, 2018

Add a logout button, performs a form post request to a logout_url.

Prop Type Default description
id string - Id of the button.
label string logout Text of the button
logout_url string - Url to submit a post logout request.
style object - style of the button.
className string - CSS class for the button.

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Nov 20, 2018

@T4rk1n T4rk1n requested a review from chriddyp November 20, 2018 19:56
Copy link

@scjody scjody left a comment

Choose a reason for hiding this comment

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

Would it make sense to automatically set the default logout_url if DASH_LOGOUT_URL exists in the environment as discussed at https://github.com/plotly/streambed/issues/11817#issuecomment-438801947?

I leave it up to the dash team to decide if this is worth doing, but without this all Dash Apps wanting to add a logout button on DDS will have to implement this so there's a good argument for centralizing it in dcc.

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Nov 20, 2018

@scjody

There is no python hooks for the components so we can't do it at the component level. Can add it from a dds app with dcc.LogoutButton(logout_url=os.getenv('DASH_LOGOUT_URL')).

@scjody
Copy link

scjody commented Nov 21, 2018

That URL doesn't look so bad, except you'll want a default so it doesn't crash in test environments and for non-DDS users. So something like: dcc.LogoutButton(logout_url=os.getenv('DASH_LOGOUT_URL', 'https://dash.plot.ly/docs_on_logout'))

Is it impossible to check DASH_LOGOUT_URL in this function? (I don't know how LogoutButton.py gets generated so I accept that it may not be, but it seems strange that we wouldn't have control over the backend of all our components.)

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Nov 21, 2018

The python component class is auto-generated, it will get overwritten when the components are regenerated.

@scjody
Copy link

scjody commented Nov 21, 2018

I realize that, but I'm surprised we don't have any control over the generation process or what goes into the component at that time.

Anyway if my suggestion is unreasonable I'm OK leaving things as they are.

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Nov 21, 2018

W could have some kind of hooks, it's just not implemented right now. I created an issue:

plotly/dash#464

className="dash-logout-frame"
>
<button
className={`dash-logout-btn ${className}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

Here if className is undefined, it will add "undefined" to the class. Would be cleaner to check if className exists before appending it.

Copy link
Contributor

@valentijnnieman valentijnnieman left a comment

Choose a reason for hiding this comment

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

I'm getting 405 errors, saying "The method is not allowed for the requested URL.". Is there something we have to set-up in the underlying Flask server to allow for POST requests? Not sure why I'm getting these errors.

For the default url, how about adding it as a defaultProp? You could even do a GET instead of a POST if there's no url set (and therefore uses the default "https://dash.plot.ly/docs_on_logout") so that it links you to those docs.

Lastly, requesting a small change having to do with appending the className prop.

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Nov 28, 2018

@valentijnnieman

There's an example in the test:

@app.server.route('/_logout', methods=['POST'])
def on_logout():
      rep = flask.redirect('/logged-out')
      rep.set_cookie('logout-cookie', '', 0)
      return rep

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Nov 28, 2018

I'll make https://dash.plot.ly/dash-core-components/logout_button the default url and adds documentation and examples there when released.

@valentijnnieman
Copy link
Contributor

@T4rk1n Maybe add some more info (or a link to those docs) in the docstring for the component as well, so that it's more clear for users what this component is for.

@valentijnnieman
Copy link
Contributor

Great - looks good to me!

@T4rk1n T4rk1n merged commit 074bca8 into master Nov 29, 2018
@T4rk1n T4rk1n deleted the logout-btn branch November 29, 2018 21:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants