Fix refresh token mecanism.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.codiki.application.picture;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@@ -31,6 +32,7 @@ public class PictureUseCases {
|
||||
.withId(UUID.randomUUID())
|
||||
.withPublisher(authenticatedUser)
|
||||
.withContentFile(pictureFile)
|
||||
.withPublicationDate(ZonedDateTime.now())
|
||||
.build();
|
||||
|
||||
picturePort.save(newPicture);
|
||||
|
||||
@@ -31,6 +31,7 @@ public class PictureEntity {
|
||||
public PictureEntity(Picture picture) {
|
||||
id = picture.id();
|
||||
publisherId = picture.publisherId();
|
||||
publishedAt = picture.publishedAt();
|
||||
}
|
||||
|
||||
public Picture toDomain() {
|
||||
|
||||
@@ -49,6 +49,7 @@ export class JwtInterceptor implements HttpInterceptor {
|
||||
this.userRestService.refreshToken(refreshTokenRequest)
|
||||
.then(refreshTokenResponse => {
|
||||
this.authenticationService.authenticate(refreshTokenResponse.accessToken, refreshTokenResponse.refreshToken);
|
||||
this.refreshTokenSubject.next(refreshTokenResponse.accessToken);
|
||||
})
|
||||
.catch(() => {
|
||||
return this.handleNoRefreshToken(initialError);
|
||||
|
||||
@@ -29,16 +29,7 @@ export class AuthenticationService {
|
||||
}
|
||||
|
||||
isAuthenticated(): boolean {
|
||||
let result = false;
|
||||
|
||||
const userDetails = this.extractUserDetails();
|
||||
|
||||
if (userDetails) {
|
||||
const authenticationExpiration = new Date(userDetails.exp * 1000);
|
||||
result = authenticationExpiration > new Date();
|
||||
}
|
||||
|
||||
return result;
|
||||
return !!localStorage.getItem(JWT_PARAM);
|
||||
}
|
||||
|
||||
getAuthenticatedUser(): User | undefined {
|
||||
|
||||
@@ -53,7 +53,18 @@ export class PictureSelectionDialog implements OnInit {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
|
||||
uploadPicture(file: any): void {
|
||||
console.log("uploadFile", file);
|
||||
uploadPicture(fileSelectionEvent: any): void {
|
||||
const pictureFile = fileSelectionEvent.target.files[0];
|
||||
if (pictureFile) {
|
||||
this.pictureRestService.uploadPicture(pictureFile)
|
||||
.then(pictureId => {
|
||||
this.dialogRef.close(pictureId);
|
||||
})
|
||||
.catch(error => {
|
||||
const errorMessage = 'A technical error occured while uploading your picture.';
|
||||
console.error(errorMessage, error);
|
||||
this.snackBar.open(errorMessage, 'Close', { duration: 5000 });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user