Skip to content

Commit

Permalink
Merge pull request #21 from williamhatcher/master
Browse files Browse the repository at this point in the history
Add Unauthorized redirect to basic usage
  • Loading branch information
weibeu committed Jul 15, 2020
2 parents d552a04 + 8d40b1a commit 79b6d56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ python3 -m pip install Flask-Discord
### Basic Example
```python
from flask import Flask, redirect, url_for
from flask_discord import DiscordOAuth2Session, requires_authorization
from flask_discord import DiscordOAuth2Session, requires_authorization, Unauthorized

app = Flask(__name__)

Expand All @@ -37,7 +37,12 @@ def login():
def callback():
discord.callback()
return redirect(url_for(".me"))



@app.errorhandler(Unauthorized)
def redirect_unauthorized(e):
return redirect(url_for("login"))


@app.route("/me/")
@requires_authorization
Expand Down
9 changes: 7 additions & 2 deletions docs/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ in exchange for fetching user's details and display them on web page.
.. code-block:: python3
from flask import Flask, redirect, url_for
from flask_discord import DiscordOAuth2Session, requires_authorization
from flask_discord import DiscordOAuth2Session, requires_authorization, Unauthorized
app = Flask(__name__)
Expand All @@ -69,6 +69,11 @@ in exchange for fetching user's details and display them on web page.
return redirect(url_for(".me"))
@app.errorhandler(Unauthorized)
def redirect_unauthorized(e):
return redirect(url_for("login"))
@app.route("/me/")
@requires_authorization
def me():
Expand All @@ -85,4 +90,4 @@ in exchange for fetching user's details and display them on web page.
if __name__ == "__main__":
app.run()
app.run()

0 comments on commit 79b6d56

Please sign in to comment.