Skip to content

Commit

Permalink
refactor(api_lint_errors): Remove linting errors from app/api folder
Browse files Browse the repository at this point in the history
  • Loading branch information
deo002 authored and heliocastro committed Oct 28, 2024
1 parent a20693e commit 8a137e7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/app/api/auth/[...nextauth]/basicAuthOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CREDENTIAL_PROVIDER } from '@/constants'
import AuthService from '@/services/auth.service'
import { HttpStatus, UserCredentialInfo } from '@/object-types'
import { ApiUtils } from '@/utils'
import { NextAuthOptions } from 'next-auth'
import { NextAuthOptions, User } from 'next-auth'

const basicAuthOption: NextAuthOptions = {
providers: [
Expand Down Expand Up @@ -53,7 +53,7 @@ const basicAuthOption: NextAuthOptions = {

callbacks: {
async jwt({ token, user }) {
return { ...token, ...user }
return { ...token, ...user } as User
},
async session({ session, token }) {
session.user = token
Expand Down
11 changes: 3 additions & 8 deletions src/app/api/auth/[...nextauth]/keycloakAuthOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import KeycloakProvider from "next-auth/providers/keycloak";
import { NextAuthOptions } from 'next-auth'
import { jwtDecode } from 'jwt-decode'

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

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

callbacks: {
async jwt({ token, account }) {
const nowTimeStamp = Math.floor(Date.now() / 1000)
if (account) {
if (account && account.access_token && account.id_token && account.expires_at && account.refresh_token) {
token.decoded = jwtDecode(account.access_token)
token.access_token = "Bearer " + account.id_token
token.expires_in = account.expires_at
token.refresh_token = account.refresh_token
const tokenDetails = JSON.parse(JSON.stringify(token.decoded))
const userGroup = getUserGroup(tokenDetails)
token.userGroup = Array.isArray(userGroup) ? userGroup[0] : userGroup;
return token
} else if (nowTimeStamp < token.expires_in) {
return token
} else {
console.log('Token is expired!!')
}
return token
},
async session({ session, token }) {
// Send properties to the client, like an access_token from a provider.
Expand Down
7 changes: 3 additions & 4 deletions src/app/api/auth/[...nextauth]/sw360OauthOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

// Some portions generated by Co-Pilot

import { SW360User } from '../../../../../nextauth'
import crypto from 'crypto';
import { SW360_API_URL, SW360_REST_CLIENT_ID, SW360_REST_CLIENT_SECRET } from '@/utils/env';
import { NextAuthOptions } from 'next-auth';
import { NextAuthOptions, User } from 'next-auth';

let codeVerifier: crypto.BinaryLike;

Expand Down Expand Up @@ -49,7 +48,7 @@ const sw360OauthOption: NextAuthOptions = {
email: profiles.email,
access_token: 'Bearer ' + tokens.access_token,
id: profiles.sub,
} as SW360User;
} as User
},
}
],
Expand All @@ -60,7 +59,7 @@ const sw360OauthOption: NextAuthOptions = {

callbacks: {
async jwt({ token, user }) {
return { ...token, ...user }
return { ...token, ...user } as User
},
async session({ session, token }) {
// Send properties to the client, like an access_token from a provider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { CREDENTIAL_PROVIDER } from '@/constants'
import AuthService from '@/services/auth.service'
import { HttpStatus, UserCredentialInfo } from '@/object-types'
import { ApiUtils } from '@/utils'
import { NextAuthOptions } from 'next-auth'
import { NextAuthOptions, User } from 'next-auth'

const sw360OauthPwdGrantTypeOption: NextAuthOptions = {
providers: [
Expand Down Expand Up @@ -54,7 +54,7 @@ const sw360OauthPwdGrantTypeOption: NextAuthOptions = {

callbacks: {
async jwt({ token, user }) {
return { ...token, ...user }
return { ...token, ...user } as User
},
async session({ session, token }) {
// Send properties to the client, like an access_token from a provider.
Expand Down

0 comments on commit 8a137e7

Please sign in to comment.