now I have created a Directus
application, and am using it as a back-end .. and am letting the user log in from another external domain and form Django
app and sending post request to be able to login .. how to stop Derictus
from asking him to log in again after i redirect him to the Directus admin panel link after login success ?
here are some of the codes I have used for the whole process :
docekr-compose.yaml for the Directus
part :
version: "3"
services:
db:
image: ${DB_IMAGE}
container_name: ${DB_CONTAINER_NAME}
volumes:
- ${DB_VOLUME}
ports:
- '${DB_PORT}:5432'
restart: always
environment:
- POSTGRES_DB=${DB_DATABASE}
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
# - PGDATA=/tmp
directus:
image: directus/directus:10.7.1
container_name: ${WEB_CONTAINER_NAME}
ports:
- ${APP_PORT}:8055
restart: always
volumes:
- ./uploads:/directus/uploads
environment:
KEY: ${KEY}
SECRET: ${SECRET}
ADMIN_EMAIL: ${ADMIN_EMAIL}
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
DB_CLIENT: ${DB_CLIENT}
DB_FILENAME: ${DB_FILENAME}
DB_HOST: ${DB_HOST}
DB_PORT: 5432
DB_DATABASE: ${DB_DATABASE}
DB_USER: ${DB_USER}
DB_PASSWORD: ${DB_PASSWORD}
WEBSOCKETS_ENABLED: true
depends_on:
- db
and my Django logic :
def authenticate_user(request):
print("function called")
if request.method == 'POST':
email = request.POST.get('email')
password = request.POST.get('password')
# Create a JSON payload
data = {
"email": email,
"password": password
}
# Send a POST request to the external API
url = "http://<my_domain>:<port>/auth/login"
headers = {'Content-Type': 'application/json'}
response = requests.post(url, data=json.dumps(data), headers=headers)
if response.status_code == 200:
# If the response is successful, print it in the console
print(response.json())
# Redirect the user to the given URL
return redirect("http://<my_domain>:<port>/")
else:
print(response.json())
return redirect('login_page')
else:
print(response.json())
return redirect('login_page')
please note i have changed <my_doman>
and <port>
with the real data