Skip to content

Commit

Permalink
fix: violations of upcoming eslint/no-else-return oxlint rule (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac authored Oct 10, 2024
1 parent a070447 commit 734953f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 39 deletions.
11 changes: 5 additions & 6 deletions playground-authjs/server/api/auth/[...].ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ export default NuxtAuthHandler({
// Any object returned will be saved in `user` property of the JWT
return user
}
else {
console.error('Warning: Malicious login attempt registered, bad credentials provided')

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

// 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
}
// If you return null then an error will be displayed advising the user to check their details.
return null

// 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
}
})
]
Expand Down
6 changes: 2 additions & 4 deletions src/runtime/composables/commonAuthState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ export function makeCommonAuthState<SessionData>() {
if (loading.value) {
return 'loading'
}
else if (data.value) {
if (data.value) {
return 'authenticated'
}
else {
return 'unauthenticated'
}
return 'unauthenticated'
})

// Determine base url of app
Expand Down
9 changes: 3 additions & 6 deletions src/runtime/composables/local/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ async function getSession(getSessionOptions?: GetSessionOptions): Promise<Sessio
if (onUnauthenticated) {
return onUnauthenticated()
}
else {
await navigateTo(callbackUrl ?? await getRequestURLWN(nuxt), { external })
}
await navigateTo(callbackUrl ?? await getRequestURLWN(nuxt), { external })
}

return data.value
Expand Down Expand Up @@ -220,9 +218,8 @@ async function refresh(getSessionOptions?: GetSessionOptions) {
)
return
}
else {
rawRefreshToken.value = extractedRefreshToken
}

rawRefreshToken.value = extractedRefreshToken
}

rawToken.value = extractedToken
Expand Down
28 changes: 13 additions & 15 deletions src/runtime/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,21 @@ export default defineNuxtRouteMiddleware((to) => {
// @ts-ignore This is valid for a backend-type of `authjs`, where sign-in accepts a provider as a first argument
return signIn(undefined, signInOptions) as ReturnType<typeof navigateToAuthPages>
}
else if (typeof metaAuth === 'object' && metaAuth.navigateUnauthenticatedTo) {
if (typeof metaAuth === 'object' && metaAuth.navigateUnauthenticatedTo) {
return navigateTo(metaAuth.navigateUnauthenticatedTo)
}
else {
if (typeof globalAppMiddleware === 'object' && globalAppMiddleware.addDefaultCallbackUrl) {
let redirectUrl: string = to.fullPath
if (typeof globalAppMiddleware.addDefaultCallbackUrl === 'string') {
redirectUrl = globalAppMiddleware.addDefaultCallbackUrl
}

return navigateTo({
path: authConfig.provider.pages.login,
query: {
redirect: redirectUrl
}
})
if (typeof globalAppMiddleware === 'object' && globalAppMiddleware.addDefaultCallbackUrl) {
let redirectUrl: string = to.fullPath
if (typeof globalAppMiddleware.addDefaultCallbackUrl === 'string') {
redirectUrl = globalAppMiddleware.addDefaultCallbackUrl
}
return navigateTo(authConfig.provider.pages.login)

return navigateTo({
path: authConfig.provider.pages.login,
query: {
redirect: redirectUrl
}
})
}
return navigateTo(authConfig.provider.pages.login)
})
4 changes: 1 addition & 3 deletions src/runtime/plugins/refresh-token.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ export default defineNuxtPlugin({
)
return
}
else {
rawRefreshToken.value = extractedRefreshToken
}
rawRefreshToken.value = extractedRefreshToken
}

rawToken.value = extractedToken
Expand Down
8 changes: 3 additions & 5 deletions src/runtime/server/services/authjs/nuxtAuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,10 @@ function getRequestBaseFromH3Event(event: H3Event, trustHost: boolean): string {

return `${protocol}://${host}`
}
else {
// This may throw, we don't catch it
const origin = getServerOrigin(event)
// This may throw, we don't catch it
const origin = getServerOrigin(event)

return origin
}
return origin
}

/** Actions supported by auth handler */
Expand Down

0 comments on commit 734953f

Please sign in to comment.