[Bug] [Anvil App Server v1.6.5] anvil.users.force_login and anvil.users.login_with_email

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
1 Like

Moving over our discussion from GitHub, as this is the better venue for this:

To follow up: What steps should I follow to see this issue for myself?

Hi @meredydd,

I follow these steps:
1.

  1. Clone the app here:
    Anvil Docs | Custom user authentication

  2. On the client side, change this

anvil.users.login_with_email(d.email_box.text, d.password_box.text, remember=True)

to this

anvil.server.call('my_login',d.email_box.text, d.password_box.text)

server side code:

@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
1 Like

Hi @meredydd, are you able to produce the same error with the steps?

I try running the app with the Anvil docker image, and the same error happens as well.

Hi,

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

Also make sure that the anvil.yaml file contains the db_schema and user service. I find using git the best option to keep this in sync.

db_schema:
users:
title: Users
client: none
server: full
columns:
- name: email
admin_ui: {width: 200}
type: string
- name: enabled
admin_ui: {width: 200}
type: bool
etc

Thanks so much @j.vanrenen, I really appreciate your help