Skip to content

Commit

Permalink
add contstants
Browse files Browse the repository at this point in the history
  • Loading branch information
fedden committed Feb 12, 2021
1 parent e753927 commit 645136a
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions gotrue/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
====================================
core module of the project
"""
import datetime
import functools
import json
import requests
import re
import uuid
from typing import Any, Callable, Dict, Optional
from urllib.parse import quote

HTTPRegexp = "/^http://"
defaultApiURL = "/.netlify/identity"
from gotrue.api import GoTrueApi
from gotrue.libs.contants import GOTRUE_URL, STORAGE_KEY


def jsonify(dictionary: dict):
return json.dumps(dictionary)
HTTPRegexp = "/^http://"
defaultApiURL = "/.netlify/identity"


class Client:
Expand Down Expand Up @@ -72,8 +71,8 @@ def sign_up(self, email: str, password: str):
The user's password.
"""
self._remove_session()
data = self.api.sign_up(email, password)
if data.user.confirmed_at:
data = self.api.sign_up_with_email(email, password)
if "confirmed_at" in data.get("user", {}):
self._save_session(data)
self._notify_all_subscribers("SIGNED_IN")
return data
Expand Down Expand Up @@ -184,7 +183,7 @@ def _save_session(self, session):
self._persist_session(self.current_session, token_expiry_seconds)

def _persist_session(self, current_session, seconds_to_expiry: int):
timenow_seconds: int = datetime.datetime.now()
timenow_seconds: int = int(round(datetime.datetime.now().timestamp()))
expires_at: int = timenow_seconds + seconds_to_expiry
data = {
"current_session": current_session,
Expand All @@ -211,11 +210,11 @@ def _call_refresh_token(self, refresh_token: Optional[str] = None):
elif refresh_token is None:
raise ValueError("No current session and refresh_token not supplied.")
data = self.api.refresh_access_token(refresh_token)
if data is not None and "access_token" in data:
if "access_token" in data:
self.current_session = data
self.current_user = data.user
self._notify_all_subscribers("SIGNED_IN")
token_expiry_seconds = data.get("expires_in")
token_expiry_seconds: int = data["expires_in"]
if self.auto_refresh_token and token_expiry_seconds is not None:
self._set_timeout(
self._call_refresh_token, (token_expiry_seconds - 60) * 1000
Expand All @@ -228,3 +227,8 @@ def _notify_all_subscribers(self, event: str):
"""Notify all subscribers that auth event happened."""
for value in self.state_change_emitters.values():
value["callback"](event, self.current_session)

def _set_timeout(*args, **kwargs):
""""""
# TODO(fedden): Implement JS equivalent of setTimeout method.
pass

0 comments on commit 645136a

Please sign in to comment.