How can I protect my endpoints? #2968
-
Hello, I am using svelteKit building my app. I ran into a problem: How can I protect endpoints? Here is my folder structure: src:.
│ app.css
│ app.html
│ global.d.ts
│ hooks.js
│ stores.js
├─lib
│ db.js
│ helpers.js
│ logger.js
│ Login.svelte
│ Register.svelte
└─routes
│ index.svelte
│ login.svelte
│ __layout.svelte
├─api
│ │ captcha.js
│ │ login.js
│ ├─auths
│ │ index.js
│ └─profiles
│ index.js
│ [profileId].js
└─profile
index.svelte I put my endpoints under the folder fetch("/api/profiles")
.then(res=>res.json())
.then(data=>{
// using data
})
.catch(err=>{
// handle err
}) This works fine, But the problem is: Everybody can open How can I protect my endpoints? |
Beta Was this translation helpful? Give feedback.
Answered by
benthillerkus
Dec 2, 2021
Replies: 1 comment 3 replies
-
Either in the endpoint or in hooks.js you can check if the request is authorised - for example by using the Authorization HTTP header |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
xiayulu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Either in the endpoint or in hooks.js you can check if the request is authorised - for example by using the Authorization HTTP header