Skip to content

Commit 8a137e7

Browse files
deo002heliocastro
authored andcommitted
refactor(api_lint_errors): Remove linting errors from app/api folder
1 parent a20693e commit 8a137e7

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

src/app/api/auth/[...nextauth]/basicAuthOption.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { CREDENTIAL_PROVIDER } from '@/constants'
1212
import AuthService from '@/services/auth.service'
1313
import { HttpStatus, UserCredentialInfo } from '@/object-types'
1414
import { ApiUtils } from '@/utils'
15-
import { NextAuthOptions } from 'next-auth'
15+
import { NextAuthOptions, User } from 'next-auth'
1616

1717
const basicAuthOption: NextAuthOptions = {
1818
providers: [
@@ -53,7 +53,7 @@ const basicAuthOption: NextAuthOptions = {
5353

5454
callbacks: {
5555
async jwt({ token, user }) {
56-
return { ...token, ...user }
56+
return { ...token, ...user } as User
5757
},
5858
async session({ session, token }) {
5959
session.user = token

src/app/api/auth/[...nextauth]/keycloakAuthOption.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import KeycloakProvider from "next-auth/providers/keycloak";
1111
import { NextAuthOptions } from 'next-auth'
1212
import { jwtDecode } from 'jwt-decode'
1313

14-
import UserGroupType from '../../../../object-types/enums/UserGroupType';
14+
import { UserGroupType } from '@/object-types';
1515

1616
const keycloakProvider = KeycloakProvider({
1717
clientId: `${process.env.SW360_KEYCLOAK_CLIENT_ID}`,
@@ -31,21 +31,16 @@ const keycloakAuthOption: NextAuthOptions = {
3131

3232
callbacks: {
3333
async jwt({ token, account }) {
34-
const nowTimeStamp = Math.floor(Date.now() / 1000)
35-
if (account) {
34+
if (account && account.access_token && account.id_token && account.expires_at && account.refresh_token) {
3635
token.decoded = jwtDecode(account.access_token)
3736
token.access_token = "Bearer " + account.id_token
3837
token.expires_in = account.expires_at
3938
token.refresh_token = account.refresh_token
4039
const tokenDetails = JSON.parse(JSON.stringify(token.decoded))
4140
const userGroup = getUserGroup(tokenDetails)
4241
token.userGroup = Array.isArray(userGroup) ? userGroup[0] : userGroup;
43-
return token
44-
} else if (nowTimeStamp < token.expires_in) {
45-
return token
46-
} else {
47-
console.log('Token is expired!!')
4842
}
43+
return token
4944
},
5045
async session({ session, token }) {
5146
// Send properties to the client, like an access_token from a provider.

src/app/api/auth/[...nextauth]/sw360OauthOption.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99

1010
// Some portions generated by Co-Pilot
1111

12-
import { SW360User } from '../../../../../nextauth'
1312
import crypto from 'crypto';
1413
import { SW360_API_URL, SW360_REST_CLIENT_ID, SW360_REST_CLIENT_SECRET } from '@/utils/env';
15-
import { NextAuthOptions } from 'next-auth';
14+
import { NextAuthOptions, User } from 'next-auth';
1615

1716
let codeVerifier: crypto.BinaryLike;
1817

@@ -49,7 +48,7 @@ const sw360OauthOption: NextAuthOptions = {
4948
email: profiles.email,
5049
access_token: 'Bearer ' + tokens.access_token,
5150
id: profiles.sub,
52-
} as SW360User;
51+
} as User
5352
},
5453
}
5554
],
@@ -60,7 +59,7 @@ const sw360OauthOption: NextAuthOptions = {
6059

6160
callbacks: {
6261
async jwt({ token, user }) {
63-
return { ...token, ...user }
62+
return { ...token, ...user } as User
6463
},
6564
async session({ session, token }) {
6665
// Send properties to the client, like an access_token from a provider.

src/app/api/auth/[...nextauth]/sw360OauthPwdGrantTypeOption.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { CREDENTIAL_PROVIDER } from '@/constants'
1414
import AuthService from '@/services/auth.service'
1515
import { HttpStatus, UserCredentialInfo } from '@/object-types'
1616
import { ApiUtils } from '@/utils'
17-
import { NextAuthOptions } from 'next-auth'
17+
import { NextAuthOptions, User } from 'next-auth'
1818

1919
const sw360OauthPwdGrantTypeOption: NextAuthOptions = {
2020
providers: [
@@ -54,7 +54,7 @@ const sw360OauthPwdGrantTypeOption: NextAuthOptions = {
5454

5555
callbacks: {
5656
async jwt({ token, user }) {
57-
return { ...token, ...user }
57+
return { ...token, ...user } as User
5858
},
5959
async session({ session, token }) {
6060
// Send properties to the client, like an access_token from a provider.

0 commit comments

Comments
 (0)