Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/eden/treaty/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { treaty } from '@elysiajs/eden'

const app = new Elysia()
.post('/user', ({ body: { name }, status }) => {
if(name === 'Otto') return status(400)
if(name === 'Otto') return status('Bad Request')

return name
}, {
Expand Down Expand Up @@ -146,7 +146,7 @@ import { treaty, Treaty } from '@elysiajs/eden'

const app = new Elysia()
.post('/user', ({ body: { name }, status }) => {
if(name === 'Otto') return status(400)
if(name === 'Otto') return status('Bad Request')

return name
}, {
Expand Down
6 changes: 3 additions & 3 deletions docs/essential/best-practice.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -367,7 +367,7 @@ class AuthService {
// ❌ Don't do this
isSignIn({ status, cookie: { session } }: Context) {
if (session.value)
return status(401)
return status('Unauthorized')
}
}
```
Expand All @@ -390,7 +390,7 @@ class AuthService {
// ✅ Do
isSignIn({ status, cookie: { session } }: InferContext<typeof setup>) {
if (session.value)
return status(401)
return status('Unauthorized')
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/essential/life-cycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ import { validateSession } from './user'
new Elysia()
.get('/', () => 'hi', {
beforeHandle({ set, cookie: { session }, status }) {
if (!validateSession(session.value)) return status(401)
if (!validateSession(session.value)) return status('Unauthorized')
}
})
.listen(3000)
Expand All @@ -527,7 +527,7 @@ new Elysia()
.guard(
{
beforeHandle({ set, cookie: { session }, status }) {
if (!validateSession(session.value)) return status(401)
if (!validateSession(session.value)) return status('Unauthorized')
}
},
(app) =>
Expand Down
10 changes: 5 additions & 5 deletions docs/essential/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,22 @@ 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)
// This will NOT have sign in check
.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'))
</script>

# Plugin <TutorialBadge href="/tutorial/getting-started/plugin" />
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const role = new Elysia({ name: 'macro' })
role: (type: 'user' | 'staff' | 'admin') => ({
beforeHandle({ headers, status }) {
if(headers.authorization !== type)
return status(401)
return status('Unauthorized')
}
})
})
Expand Down Expand Up @@ -159,7 +159,7 @@ export const auth = new Elysia()
ssid: t.String()
}),
resolve({ cookie, status }) {
if(!cookie.ssid.value) return status(401)
if(!cookie.ssid.value) return status('Unauthorized')

return {
user: cookie.ssid.value
Expand Down Expand Up @@ -189,7 +189,7 @@ export const auth = new Elysia()
ssid: t.String()
}),
resolve({ cookie, status }) {
if(!cookie.ssid.value) return status(401)
if(!cookie.ssid.value) return status('Unauthorized')

return {
user: cookie.ssid.value
Expand Down
2 changes: 1 addition & 1 deletion docs/integrations/better-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const betterAuth = new Elysia({ name: 'better-auth' })
headers
})

if (!session) return status(401)
if (!session) return status('Unauthorized')

return {
user: session.user,
Expand Down
10 changes: 5 additions & 5 deletions docs/key-concept.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ import { Elysia } from 'elysia'
import Playground from './components/nearl/playground.vue'

const profile1 = new Elysia()
.onBeforeHandle(({ status }) => status(401))
.get('/profile', ({ status }) => status(401))
.onBeforeHandle(({ status }) => status('Unauthorized'))
.get('/profile', ({ status }) => status('Unauthorized'))

const demo1 = new Elysia()
.use(profile1)
// This will NOT have sign in check
.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 demo2 = new Elysia()
.use(profile2)
// This will NOT have sign in check
.patch('/rename', ({ status }) => status(401))
.patch('/rename', ({ status }) => status('Unauthorized'))
</script>

# Key Concept <Badge type="danger" text="MUST READ" />
Expand Down
2 changes: 1 addition & 1 deletion docs/patterns/extends-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ new Elysia()
.derive(({ headers, status }) => {
const auth = headers['authorization']

if(!auth) return status(400)
if(!auth) return status('Unauthorized')

return {
bearer: auth?.startsWith('Bearer ') ? auth.slice(7) : null
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial/getting-started/encapsulation/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
)

Expand All @@ -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')
}
})

Expand Down
14 changes: 7 additions & 7 deletions docs/tutorial/getting-started/encapsulation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const profile1 = new Elysia()
.onBeforeHandle(
({ query: { name }, status }) => {
if(!name)
return status(401)
return status('Unauthorized')
}
)
.get('/profile', () => 'Hi!')
Expand All @@ -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)
Expand All @@ -70,7 +70,7 @@ const profile = new Elysia()
.onBeforeHandle(
({ query: { name }, status }) => {
if(!name)
return status(401)
return status('Unauthorized')
}
)
.get('/profile', () => 'Hi!')
Expand Down Expand Up @@ -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!')
Expand Down Expand Up @@ -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')
}
)

Expand All @@ -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')
}
})

Expand Down
8 changes: 4 additions & 4 deletions docs/tutorial/getting-started/guard/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 --]
Expand All @@ -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 ++]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}!`
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/getting-started/life-cycle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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}!`
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/getting-started/validation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ new Elysia()
.get('/', ({ status, set }) => {
set.headers['x-powered-by'] = 'Elysia'

return status(418, 'Hello Elysia!')
return status("I'm a teapot", 'Hello Elysia!')
})
.get('/docs', ({ redirect }) => redirect('https://elysiajs.com'))
.listen(3000)
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/patterns/extends-context/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ new Elysia()
)
})
.resolve(({ query: { age }, status }) => {
if(!age) return status(401)
if(!age) return status('Unauthorized')

return { age }
})
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial/patterns/macro/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ new Elysia()
}),
// psuedo auth check
beforeHandle({ cookie: { session }, status }) {
if(!session.value) return status(401)
if(!session.value) return status('Unauthorized')
}
})
.post('/user', ({ body }) => body, {
Expand Down Expand Up @@ -112,7 +112,7 @@ new Elysia()
.macro('isFibonacci', {
body: t.Number(),
beforeHandle({ body, status }) {
if(!isFibonacci(body)) return status(418)
if(!isFibonacci(body)) return status("I'm a teapot")
}
})
.post('/', ({ body }) => body, {
Expand Down