What I’m trying to do:
The below code works fine on the cloud Anvil but get error when using the Anvil App Server v1.6.5
@anvil.server.callable
def my_login(email, password):
user = app_tables.users.get(email=email)
if user is not None:
print (type(user))
#anvil.users.force_login(user)
#anvil.users.login_with_email(email=email, password = password,remember=True)
else:
return "Wrong info"
anvil.users.login_with_email(email=email, password = password,remember=True)
TableError: This table cannot be written or searched by this app
anvil.users.force_login(user)
InternalError: force_login() must be passed a row from the users table
@anvil.server.callable
def my_login(email, password):
user = app_tables.users.get(email = email)
if user is not None:
user['confirmed_email'] = True
anvil.users.login_with_email(email, password, remember=True)
else:
return "wrong data"
pass
Not sure if it helps but I have a similar approach based on that example. However in my app the actual ‘login’ happens from the client not the server. The server call only returns if an error was found.
if choice == 'login':
username = d.username_box.text
user_email = f"{username}@blobber.nl"
err = anvil.server.call('_user_login', user_email, username, d.password_box.text)
if err is not None:
d.login_err_lbl.text = err
d.login_err_lbl.visible = True
else:
try:
anvil.users.login_with_email(user_email, d.password_box.text, remember=True)
except anvil.users.AuthenticationFailed as e:
d.login_err_lbl.text = str(e.args[0])
d.login_err_lbl.visible = True