Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Felioh committed May 5, 2024
1 parent 25981d5 commit 14fd225
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 7 additions & 2 deletions apps/auth/src/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
BadRequestException,
Injectable,
NotAcceptableException,
UnauthorizedException,
} from '@nestjs/common';
import { UsersService } from './users/users.service';
Expand Down Expand Up @@ -97,15 +98,19 @@ export class AuthService {
});
const user = await this.userModel.findOne({ username: payload.username });
if (!user) {
throw new RpcException(new UnauthorizedException());
throw new RpcException(
new NotAcceptableException('invalid refresh token'),
);
}

return {
access_token: await this.createAccessToken(user.username, user._id),
refresh_token: await this.createRefreshToken(user.username),
};
} catch (error) {
throw new RpcException(new UnauthorizedException('Invalid token'));
throw new RpcException(
new NotAcceptableException('invalid refresh token'),
);
}
}
}
10 changes: 5 additions & 5 deletions frontend/interceptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const instance = axios.create({
baseURL: baseUrl,
});

const refreshInstance = axios.create({
//TODO besser machen
baseURL: baseUrl,
});
// const refreshInstance = axios.create({
// //TODO besser machen
// baseURL: baseUrl,
// });

let isRefreshing = false;

Expand Down Expand Up @@ -52,7 +52,7 @@ async function refreshToken(url) {
const cookies = getCookies(url);

console.log('Refreshing token');
refreshInstance
instance
.post('/auth/refresh', {}, { headers: { Cookie: cookies } })
.then((response) => {
if (response.status !== 201) {
Expand Down

0 comments on commit 14fd225

Please sign in to comment.