Skip to content

Commit 734953f

Browse files
authored
fix: violations of upcoming eslint/no-else-return oxlint rule (#921)
1 parent a070447 commit 734953f

File tree

6 files changed

+27
-39
lines changed

6 files changed

+27
-39
lines changed

playground-authjs/server/api/auth/[...].ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ export default NuxtAuthHandler({
3535
// Any object returned will be saved in `user` property of the JWT
3636
return user
3737
}
38-
else {
39-
console.error('Warning: Malicious login attempt registered, bad credentials provided')
4038

41-
// If you return null then an error will be displayed advising the user to check their details.
42-
return null
39+
console.error('Warning: Malicious login attempt registered, bad credentials provided')
4340

44-
// You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter
45-
}
41+
// If you return null then an error will be displayed advising the user to check their details.
42+
return null
43+
44+
// You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter
4645
}
4746
})
4847
]

src/runtime/composables/commonAuthState.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ export function makeCommonAuthState<SessionData>() {
2424
if (loading.value) {
2525
return 'loading'
2626
}
27-
else if (data.value) {
27+
if (data.value) {
2828
return 'authenticated'
2929
}
30-
else {
31-
return 'unauthenticated'
32-
}
30+
return 'unauthenticated'
3331
})
3432

3533
// Determine base url of app

src/runtime/composables/local/useAuth.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ async function getSession(getSessionOptions?: GetSessionOptions): Promise<Sessio
152152
if (onUnauthenticated) {
153153
return onUnauthenticated()
154154
}
155-
else {
156-
await navigateTo(callbackUrl ?? await getRequestURLWN(nuxt), { external })
157-
}
155+
await navigateTo(callbackUrl ?? await getRequestURLWN(nuxt), { external })
158156
}
159157

160158
return data.value
@@ -220,9 +218,8 @@ async function refresh(getSessionOptions?: GetSessionOptions) {
220218
)
221219
return
222220
}
223-
else {
224-
rawRefreshToken.value = extractedRefreshToken
225-
}
221+
222+
rawRefreshToken.value = extractedRefreshToken
226223
}
227224

228225
rawToken.value = extractedToken

src/runtime/middleware/auth.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,21 @@ export default defineNuxtRouteMiddleware((to) => {
101101
// @ts-ignore This is valid for a backend-type of `authjs`, where sign-in accepts a provider as a first argument
102102
return signIn(undefined, signInOptions) as ReturnType<typeof navigateToAuthPages>
103103
}
104-
else if (typeof metaAuth === 'object' && metaAuth.navigateUnauthenticatedTo) {
104+
if (typeof metaAuth === 'object' && metaAuth.navigateUnauthenticatedTo) {
105105
return navigateTo(metaAuth.navigateUnauthenticatedTo)
106106
}
107-
else {
108-
if (typeof globalAppMiddleware === 'object' && globalAppMiddleware.addDefaultCallbackUrl) {
109-
let redirectUrl: string = to.fullPath
110-
if (typeof globalAppMiddleware.addDefaultCallbackUrl === 'string') {
111-
redirectUrl = globalAppMiddleware.addDefaultCallbackUrl
112-
}
113-
114-
return navigateTo({
115-
path: authConfig.provider.pages.login,
116-
query: {
117-
redirect: redirectUrl
118-
}
119-
})
107+
if (typeof globalAppMiddleware === 'object' && globalAppMiddleware.addDefaultCallbackUrl) {
108+
let redirectUrl: string = to.fullPath
109+
if (typeof globalAppMiddleware.addDefaultCallbackUrl === 'string') {
110+
redirectUrl = globalAppMiddleware.addDefaultCallbackUrl
120111
}
121-
return navigateTo(authConfig.provider.pages.login)
112+
113+
return navigateTo({
114+
path: authConfig.provider.pages.login,
115+
query: {
116+
redirect: redirectUrl
117+
}
118+
})
122119
}
120+
return navigateTo(authConfig.provider.pages.login)
123121
})

src/runtime/plugins/refresh-token.server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ export default defineNuxtPlugin({
6363
)
6464
return
6565
}
66-
else {
67-
rawRefreshToken.value = extractedRefreshToken
68-
}
66+
rawRefreshToken.value = extractedRefreshToken
6967
}
7068

7169
rawToken.value = extractedToken

src/runtime/server/services/authjs/nuxtAuthHandler.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,10 @@ function getRequestBaseFromH3Event(event: H3Event, trustHost: boolean): string {
253253

254254
return `${protocol}://${host}`
255255
}
256-
else {
257-
// This may throw, we don't catch it
258-
const origin = getServerOrigin(event)
256+
// This may throw, we don't catch it
257+
const origin = getServerOrigin(event)
259258

260-
return origin
261-
}
259+
return origin
262260
}
263261

264262
/** Actions supported by auth handler */

0 commit comments

Comments
 (0)