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

ts custom auth #609

Merged
merged 4 commits into from
Feb 1, 2024
Merged

ts custom auth #609

merged 4 commits into from
Feb 1, 2024

Conversation

johannes-vogel
Copy link
Contributor

will be develivered with cds 7.6

The TypeScript equivalent has to use the default export.

```ts
export default function custom_auth(req: any, res: any, next: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use proper types:

import { Request } from '@sap/cds';

export default function custom_auth(request: Request, response: Response, next: Function) {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The request here is the express request object. There might be types available for express as well but I'd prefer to have that snippet as simple as possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Express request doesn't have "user" property which you might want to set here. That's why I import cds type. Response can be imported from express types.
Proper typing is important for ts example. With all those anys you might as well convert it to js example. "export default" is perfectly valid in js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The cds.Request type is simply wrong as e. g. query has a completely different semantic in the express request object.

For proper type support one would need to enhance the request type of express. I'll double check for improving the snippet. If it grows too big, I'll add a comment in the snippet.

@renejeglinsky renejeglinsky enabled auto-merge (squash) February 1, 2024 05:58
@renejeglinsky renejeglinsky merged commit f51900a into main Feb 1, 2024
4 checks passed
@renejeglinsky renejeglinsky deleted the johannes-vogel-patch-1 branch February 1, 2024 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants