Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add django_auth to ninja API #94

Merged
merged 5 commits into from
Jun 19, 2024
Merged

Add django_auth to ninja API #94

merged 5 commits into from
Jun 19, 2024

Conversation

pamella
Copy link
Collaborator

@pamella pamella commented Jun 17, 2024

Issues

Resolves #57

Description

  • Add django_auth to ninja API
    • All API methods now require an authenticated user
  • Config csrf token on configAIAssistant
Screencast.from.17-06-2024.18.16.31.webm

}: {
messageId: string;
}) => Promise<void>;
deleteMessage: ({ messageId }: { messageId: string }) => Promise<void>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by fix

Comment on lines +20 to +26
OpenAPI.interceptors.request.use((request: AxiosRequestConfig) => {
const { csrftoken } = cookie.parse(document.cookie);
if (request.headers && csrftoken) {
request.headers["X-CSRFTOKEN"] = csrftoken;
}
return request;
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary due to auth=django_auth

Copy link
Member

@fjsj fjsj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but we should provide an easy way for the dev to use token auth too.
Do you think it's enough to allow the user to set the kwargs of API or provide a init_api function that we'll call on django_ai_assistant/api/views.py? See: #55

@pamella
Copy link
Collaborator Author

pamella commented Jun 18, 2024

LGTM, but we should provide an easy way for the dev to use token auth too. Do you think it's enough to allow the user to set the kwargs of API or provide a init_api function that we'll call on django_ai_assistant/api/views.py? See: #55

I'd say the init_api function can be a more robust approach. Maybe that will also reflect on the client side, we may need to provide a way for devs to set up client interceptors as well.

@fjsj
Copy link
Member

fjsj commented Jun 18, 2024

Good input. I added that to #55

@fjsj
Copy link
Member

fjsj commented Jun 18, 2024

conflict here @pamella

@pamella
Copy link
Collaborator Author

pamella commented Jun 18, 2024

conflict here @pamella

I'll fix the conflicts once #93 is merged

Base automatically changed from td/add-tests-to-views-threads to main June 19, 2024 13:11
@pamella
Copy link
Collaborator Author

pamella commented Jun 19, 2024

The conflicts have been fixed

@fjsj fjsj merged commit d4b05f3 into main Jun 19, 2024
6 checks passed
@fjsj fjsj deleted the feat/api-django-auth branch June 19, 2024 13:30
@fjsj
Copy link
Member

fjsj commented Jun 19, 2024

@amandasavluchinske please make sure to sync with main before writing more tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add auth required to Django Ninja API
2 participants