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