How to use Oscar API Login with React JS or any JavaScript framework?

266 Views Asked by At

I use Oscar API in my project. It uses httponly cookies to log in and register and other options like add to basket.

All I need is to use it with react/next js project. But I can't access cookies because of httponly cookies. So please help me with oscar API authentication.

In my react js code I already use

withcredentials true

when fetching from API.

in the Django setting I already use

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
SESSION_COOKIE_SAMESITE = None
CRSF_COOKIE_SAMESITE = None
1

There are 1 best solutions below

0
Ahmed On

I made a mistake SESSION_COOKIE_SAMESITE needs to pass a string data but I send None, all I need I send it as a string.

must use them when working with HTTP-only cookies with the Django rest framework.

CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
CORS_ALLOW_CREDENTIALS = True
SESSION_COOKIE_SAMESITE = "None" 
CSRF_COOKIE_SAMESITE = 'None'


CORS_ALLOWED_ORIGINS = [
    'http://127.0.0.1:3000',
    'http://localhost:3000',
    'https://yourdomain',
]

in react js/ next js just use withcredentials true while fetch api.