diff --git a/docs/essential/best-practice.md b/docs/essential/best-practice.md index 9e32090d..2cd0e437 100644 --- a/docs/essential/best-practice.md +++ b/docs/essential/best-practice.md @@ -316,7 +316,7 @@ const AuthService = new Elysia({ name: 'Auth.Service' }) .macro({ isSignIn: { resolve({ cookie, status }) { - if (!cookie.session.value) return status(401) + if (!cookie.session.value) return status('Unauthorized') return { session: cookie.session.value, @@ -367,7 +367,7 @@ class AuthService { // ❌ Don't do this isSignIn({ status, cookie: { session } }: Context) { if (session.value) - return status(401) + return status('Unauthorized') } } ``` @@ -390,7 +390,7 @@ class AuthService { // ✅ Do isSignIn({ status, cookie: { session } }: InferContext) { if (session.value) - return status(401) + return status('Unauthorized') } } ``` diff --git a/docs/essential/plugin.md b/docs/essential/plugin.md index 83fc00dc..55b2043b 100644 --- a/docs/essential/plugin.md +++ b/docs/essential/plugin.md @@ -115,8 +115,8 @@ const _mock3 = { } const profile1 = new Elysia() - .onBeforeHandle(({ status }) => status(401)) - .get('/profile', ({ status }) => status(401)) + .onBeforeHandle(({ status }) => status('Unauthorized')) + .get('/profile', ({ status }) => status('Unauthorized')) const scope1 = new Elysia() .use(profile1) @@ -124,13 +124,13 @@ const scope1 = new Elysia() .patch('/rename', () => 'Updated!') const profile2 = new Elysia() - .onBeforeHandle({ as: 'global' }, ({ status }) => status(401)) - .get('/profile', ({ status }) => status(401)) + .onBeforeHandle({ as: 'global' }, ({ status }) => status('Unauthorized')) + .get('/profile', ({ status }) => status('Unauthorized')) const scope2 = new Elysia() .use(profile2) // This will NOT have sign in check - .patch('/rename', ({ status }) => status(401)) + .patch('/rename', ({ status }) => status('Unauthorized')) # Plugin diff --git a/docs/tutorial/getting-started/encapsulation/data.ts b/docs/tutorial/getting-started/encapsulation/data.ts index 0df1f918..f22d3952 100644 --- a/docs/tutorial/getting-started/encapsulation/data.ts +++ b/docs/tutorial/getting-started/encapsulation/data.ts @@ -5,7 +5,7 @@ export const code = `import { Elysia, t } from 'elysia' const nameCheck = new Elysia() .onBeforeHandle( ({ query: { name }, status }) => { - if(!name) return status(401) + if(!name) return status('Unauthorized') } ) @@ -16,7 +16,7 @@ const ageCheck = new Elysia() name: t.Optional(t.String()) }), beforeHandle({ query: { age }, status }) { - if(age < 18) return status(403) + if(age < 18) return status('Forbidden') } }) diff --git a/docs/tutorial/getting-started/encapsulation/index.md b/docs/tutorial/getting-started/encapsulation/index.md index bdf9dd3c..6003edb5 100644 --- a/docs/tutorial/getting-started/encapsulation/index.md +++ b/docs/tutorial/getting-started/encapsulation/index.md @@ -30,7 +30,7 @@ const profile1 = new Elysia() .onBeforeHandle( ({ query: { name }, status }) => { if(!name) - return status(401) + return status('Unauthorized') } ) .get('/profile', () => 'Hi!') @@ -44,10 +44,10 @@ const profile2 = new Elysia() { as: 'global' }, ({ query: { name }, status }) => { if(!name) - return status(401) + return status('Unauthorized') } ) - .get('/profile', ({ status }) => status(401)) + .get('/profile', ({ status }) => status('Unauthorized')) const demo2 = new Elysia() .use(profile2) @@ -70,7 +70,7 @@ const profile = new Elysia() .onBeforeHandle( ({ query: { name }, status }) => { if(!name) - return status(401) + return status('Unauthorized') } ) .get('/profile', () => 'Hi!') @@ -143,7 +143,7 @@ const user = new Elysia() name: t.Optional(t.String()) }), beforeHandle({ query: { age }, status }) { - if(age < 18) return status(403) + if(age < 18) return status('Forbidden') } }) .get('/profile', () => 'Hi!') @@ -171,7 +171,7 @@ const nameCheck = new Elysia() .onBeforeHandle( { as: 'scoped' }, // [!code ++] ({ query: { name }, status }) => { - if(!name) return status(401) + if(!name) return status('Unauthorized') } ) @@ -183,7 +183,7 @@ const ageCheck = new Elysia() name: t.Optional(t.String()) }), beforeHandle({ query: { age }, status }) { - if(age < 18) return status(403) + if(age < 18) return status('Forbidden') } }) diff --git a/docs/tutorial/getting-started/guard/index.md b/docs/tutorial/getting-started/guard/index.md index 54722d61..e50af075 100644 --- a/docs/tutorial/getting-started/guard/index.md +++ b/docs/tutorial/getting-started/guard/index.md @@ -37,7 +37,7 @@ import { Elysia, t } from 'elysia' new Elysia() .onBeforeHandle(({ query: { name }, status }) => { // [!code --] - if(!name) return status(401) // [!code --] + if(!name) return status('Unauthorized') // [!code --] }) // [!code --] .onBeforeHandle(({ query: { name } }) => { // [!code --] console.log(name) // [!code --] @@ -48,7 +48,7 @@ new Elysia() .guard({ // [!code ++] beforeHandle: [ // [!code ++] ({ query: { name }, status }) => { // [!code ++] - if(!name) return status(401) // [!code ++] + if(!name) return status('Unauthorized') // [!code ++] }, // [!code ++] ({ query: { name } }) => { // [!code ++] console.log(name) // [!code ++] @@ -88,7 +88,7 @@ new Elysia() .guard({ beforeHandle: [ ({ query: { name }, status }) => { - if(!name) return status(401) + if(!name) return status('Unauthorized') }, ({ query: { name } }) => { console.log(name) @@ -139,7 +139,7 @@ import { Elysia } from 'elysia' new Elysia() .onBeforeHandle(({ query: { name }, status }) => { - if(!name) return status(401) + if(!name) return status('Unauthorized') }) .get('/auth', ({ query: { name = 'anon' } }) => { return `Hello ${name}!`