Cannot login in a self host environment #291

Closed
opened 2026-02-21 17:26:40 -05:00 by yindo · 2 comments
Owner

Originally created by @zhengheliu on GitHub (Jul 20, 2023).

Dify version: Self Host

Steps To Reproduce

  1. The code version is 0.3.10
  2. API .env file
# Server Edition
EDITION=SELF_HOSTED

# Your App secret key will be used for securely signing the session cookie
# Make sure you are changing this key for your deployment with a strong key.
# You can generate a strong key using `openssl rand -base64 42`.
# Alternatively you can set it with `SECRET_KEY` environment variable.
SECRET_KEY=I52Jl4TMrkiTto+G2VCuqIeB6Qqoxq8Lt3cBGiisr7IY5OqVJM+1voT1

# Console API base URL
CONSOLE_API_URL=http://192.168.31.11:5001

# Console frontend web base URL
CONSOLE_WEB_URL=http://192.168.31.11:3000

# Service API base URL
SERVICE_API_URL=http://192.168.31.11:5001

# Web APP API base URL
APP_API_URL=http://192.168.31.11:5001

# Web APP frontend web base URL
APP_WEB_URL=http://192.168.31.11:3000

# celery configuration
CELERY_BROKER_URL=redis://:difyai123456@localhost:6379/1

# redis configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_USERNAME=
REDIS_PASSWORD=difyai123456
REDIS_DB=0

# PostgreSQL database configuration
DB_USERNAME=postgres
DB_PASSWORD=difyai123456
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=dify

# Storage configuration
# use for store upload files, private keys...
# storage type: local, s3
STORAGE_TYPE=local
STORAGE_LOCAL_PATH=storage
S3_ENDPOINT=https://your-bucket-name.storage.s3.clooudflare.com
S3_BUCKET_NAME=your-bucket-name
S3_ACCESS_KEY=your-access-key
S3_SECRET_KEY=your-secret-key
S3_REGION=your-region

# CORS configuration
WEB_API_CORS_ALLOW_ORIGINS=*
CONSOLE_CORS_ALLOW_ORIGINS=*

# Cookie configuration
COOKIE_HTTPONLY=true
COOKIE_SAMESITE=None
COOKIE_SECURE=true

# Session configuration
SESSION_PERMANENT=true
SESSION_USE_SIGNER=true

## support redis, sqlalchemy
SESSION_TYPE=redis

# session redis configuration
SESSION_REDIS_HOST=localhost
SESSION_REDIS_PORT=6379
SESSION_REDIS_PASSWORD=difyai123456
SESSION_REDIS_DB=2

# Vector database configuration, support: weaviate, qdrant
VECTOR_STORE=weaviate

# Weaviate configuration
WEAVIATE_ENDPOINT=http://localhost:8080
WEAVIATE_API_KEY=WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih
WEAVIATE_GRPC_ENABLED=false
WEAVIATE_BATCH_SIZE=100

# Qdrant configuration, use `path:` prefix for local mode or `https://your-qdrant-cluster-url.qdrant.io` for remote mode
QDRANT_URL=path:storage/qdrant
QDRANT_API_KEY=your-qdrant-api-key

# Mail configuration, support: resend
MAIL_TYPE=
MAIL_DEFAULT_SEND_FROM=no-reply <no-reply@dify.ai>
RESEND_API_KEY=

# Sentry configuration
SENTRY_DSN=

# DEBUG
DEBUG=false
SQLALCHEMY_ECHO=false

# Notion import configuration, support public and internal
NOTION_INTEGRATION_TYPE=public
NOTION_CLIENT_SECRET=you-client-secret
NOTION_CLIENT_ID=you-client-id
NOTION_INTERNAL_SECRET=you-internal-secret
  1. The Web .env.local file
# For production release, change this to PRODUCTION
NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
# The deployment edition, SELF_HOSTED or CLOUD
NEXT_PUBLIC_EDITION=SELF_HOSTED
# The base URL of console application, refers to the Console base URL of WEB service if console domain is
# different from api or web app domain.
# example: http://cloud.dify.ai/console/api
NEXT_PUBLIC_API_PREFIX=http://192.168.31.11:5001/console/api
# The URL for Web APP, refers to the Web App base URL of WEB service if web app domain is different from
# console or api domain.
# example: http://udify.app/api
NEXT_PUBLIC_PUBLIC_API_PREFIX=http://192.168.31.11:5001/api

# SENTRY
NEXT_PUBLIC_SENTRY_DSN=
  1. I deploy API & web in a server in LAN, IP is 192.168.31.11
  2. I use my computer in the same LAN to access the front page http://192.168.31.11:3000

The current behavior

  1. Register is OK
  2. I cannot login, it seems the login call is unfinished in front page, and when it calls profile api, it returns 401, so the signin page show again
  3. I try to call login API in postman, it works
    1
    2

The expected behavior

  1. Should be login
Originally created by @zhengheliu on GitHub (Jul 20, 2023). <!-- Please provide a clear and concise description of what the bug is. Include screenshots if needed. Please test using the latest version of the relevant Dify packages to make sure your issue has not already been fixed. --> Dify version: Self Host ## Steps To Reproduce <!-- Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than Dify. Issues without reproduction steps or code examples may be immediately closed as not actionable. --> 1. The code version is 0.3.10 2. API .env file ``` # Server Edition EDITION=SELF_HOSTED # Your App secret key will be used for securely signing the session cookie # Make sure you are changing this key for your deployment with a strong key. # You can generate a strong key using `openssl rand -base64 42`. # Alternatively you can set it with `SECRET_KEY` environment variable. SECRET_KEY=I52Jl4TMrkiTto+G2VCuqIeB6Qqoxq8Lt3cBGiisr7IY5OqVJM+1voT1 # Console API base URL CONSOLE_API_URL=http://192.168.31.11:5001 # Console frontend web base URL CONSOLE_WEB_URL=http://192.168.31.11:3000 # Service API base URL SERVICE_API_URL=http://192.168.31.11:5001 # Web APP API base URL APP_API_URL=http://192.168.31.11:5001 # Web APP frontend web base URL APP_WEB_URL=http://192.168.31.11:3000 # celery configuration CELERY_BROKER_URL=redis://:difyai123456@localhost:6379/1 # redis configuration REDIS_HOST=localhost REDIS_PORT=6379 REDIS_USERNAME= REDIS_PASSWORD=difyai123456 REDIS_DB=0 # PostgreSQL database configuration DB_USERNAME=postgres DB_PASSWORD=difyai123456 DB_HOST=localhost DB_PORT=5432 DB_DATABASE=dify # Storage configuration # use for store upload files, private keys... # storage type: local, s3 STORAGE_TYPE=local STORAGE_LOCAL_PATH=storage S3_ENDPOINT=https://your-bucket-name.storage.s3.clooudflare.com S3_BUCKET_NAME=your-bucket-name S3_ACCESS_KEY=your-access-key S3_SECRET_KEY=your-secret-key S3_REGION=your-region # CORS configuration WEB_API_CORS_ALLOW_ORIGINS=* CONSOLE_CORS_ALLOW_ORIGINS=* # Cookie configuration COOKIE_HTTPONLY=true COOKIE_SAMESITE=None COOKIE_SECURE=true # Session configuration SESSION_PERMANENT=true SESSION_USE_SIGNER=true ## support redis, sqlalchemy SESSION_TYPE=redis # session redis configuration SESSION_REDIS_HOST=localhost SESSION_REDIS_PORT=6379 SESSION_REDIS_PASSWORD=difyai123456 SESSION_REDIS_DB=2 # Vector database configuration, support: weaviate, qdrant VECTOR_STORE=weaviate # Weaviate configuration WEAVIATE_ENDPOINT=http://localhost:8080 WEAVIATE_API_KEY=WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih WEAVIATE_GRPC_ENABLED=false WEAVIATE_BATCH_SIZE=100 # Qdrant configuration, use `path:` prefix for local mode or `https://your-qdrant-cluster-url.qdrant.io` for remote mode QDRANT_URL=path:storage/qdrant QDRANT_API_KEY=your-qdrant-api-key # Mail configuration, support: resend MAIL_TYPE= MAIL_DEFAULT_SEND_FROM=no-reply <no-reply@dify.ai> RESEND_API_KEY= # Sentry configuration SENTRY_DSN= # DEBUG DEBUG=false SQLALCHEMY_ECHO=false # Notion import configuration, support public and internal NOTION_INTEGRATION_TYPE=public NOTION_CLIENT_SECRET=you-client-secret NOTION_CLIENT_ID=you-client-id NOTION_INTERNAL_SECRET=you-internal-secret ``` 3. The Web .env.local file ``` # For production release, change this to PRODUCTION NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT # The deployment edition, SELF_HOSTED or CLOUD NEXT_PUBLIC_EDITION=SELF_HOSTED # The base URL of console application, refers to the Console base URL of WEB service if console domain is # different from api or web app domain. # example: http://cloud.dify.ai/console/api NEXT_PUBLIC_API_PREFIX=http://192.168.31.11:5001/console/api # The URL for Web APP, refers to the Web App base URL of WEB service if web app domain is different from # console or api domain. # example: http://udify.app/api NEXT_PUBLIC_PUBLIC_API_PREFIX=http://192.168.31.11:5001/api # SENTRY NEXT_PUBLIC_SENTRY_DSN= ``` 4. I deploy API & web in a server in LAN, IP is 192.168.31.11 5. I use my computer in the same LAN to access the front page http://192.168.31.11:3000 ## The current behavior 1. Register is OK 2. I cannot login, it seems the login call is unfinished in front page, and when it calls profile api, it returns 401, so the signin page show again 3. I try to call login API in postman, it works <img width="1919" alt="1" src="https://github.com/langgenius/dify/assets/1491413/7029a5e3-23c2-4b03-b29a-e995de1db7d2"> <img width="682" alt="2" src="https://github.com/langgenius/dify/assets/1491413/81369a2a-f007-4c87-9081-d09505548f83"> ## The expected behavior 1. Should be login
yindo closed this issue 2026-02-21 17:26:40 -05:00
Author
Owner

@crazywoola commented on GitHub (Jul 20, 2023):

In this part

# Cookie configuration
COOKIE_HTTPONLY=true
COOKIE_SAMESITE=None => Lax
COOKIE_SECURE=true
@crazywoola commented on GitHub (Jul 20, 2023): In this part ``` # Cookie configuration COOKIE_HTTPONLY=true COOKIE_SAMESITE=None => Lax COOKIE_SECURE=true ```
Author
Owner

@zhengheliu commented on GitHub (Jul 20, 2023):

In this part

# Cookie configuration
COOKIE_HTTPONLY=true
COOKIE_SAMESITE=None => Lax
COOKIE_SECURE=true

Since backend & frontend run in different port, cannot set samesite to Lax, the only option is None.
And if samesite is none, secure should be true, that means frontend should acess backend via https.
I add --cert=adhoc parameter to flask run, so it can server https, now it's ok, thanks!

@zhengheliu commented on GitHub (Jul 20, 2023): > In this part > > ``` > # Cookie configuration > COOKIE_HTTPONLY=true > COOKIE_SAMESITE=None => Lax > COOKIE_SECURE=true > ``` Since backend & frontend run in different port, cannot set samesite to Lax, the only option is None. And if samesite is none, secure should be true, that means frontend should acess backend via https. I add --cert=adhoc parameter to flask run, so it can server https, now it's ok, thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#291