Getting The Current User With Your Server Code

When a user logs in to your website with Weasl, a JWT is stored as a cookie that lasts for 7 days. The cookie domain is stored on you domain, and now just your subdomain. For example, if you had Weasl running on https://www.weasl.in and https://app.weasl.in you can be sure that when user goes from one to the other, they will still be logged in, because the cookie is stored on weasl.in.

Here's an example of how to get the cookie when a request comes in to a Flask Python app:

from flask import Flask, request, jsonify
import requests

app = Flask(__name__)

weasl_client_id = '123abc'
weasl_cookie_name = 'WEASL_AUTH-'.format(weasl_client_id)
get_me_url = 'https://api.weasl.in/end_users/me'

@app.route('/')
def get_current_user():
    cookie = request.cookies.get(weasl_cookie_name)
    if cookie is None:
        return 'You are not logged in'
    headers = {
        'Authorization': 'Bearer {}'.format(cookie),
        'X-Weasl-Client-Id': weasl_client_id,
    }
    res = requests.get(get_me_url, headers=headers)
    if res.status_code != 200:
        return 'Error'
    else:
        return jsonify(response=res.json())

of course, if you are using Flask and Python, you can just use the Python Flask integration for Weasl.


Did this help answer your question?

thumbs up
thumbs down

Thanks for the feedback! 🙏🏽


Help by drift