Skip to content

Commit

Permalink
fix(db): fixed invalid data types and columns
Browse files Browse the repository at this point in the history
  • Loading branch information
zZHorizonZz committed Jul 24, 2023
1 parent 6a6b350 commit 9d13e6a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
5 changes: 4 additions & 1 deletion server/src/main/java/dev/shiperist/entity/SessionEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.sql.Time;
import java.time.LocalDateTime;
import java.util.Date;

@Data
@Entity(name = "Session")
Expand All @@ -24,7 +26,8 @@ public class SessionEntity extends PanacheEntityBase {
private Long userId;

@Column(name = "expires")
private LocalDateTime expires;
@Temporal(TemporalType.TIMESTAMP)
private Date expires;

@ManyToOne
@JoinColumn(name = "user_id", insertable = false, updatable = false)
Expand Down
9 changes: 6 additions & 3 deletions server/src/main/java/dev/shiperist/entity/UserEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.sql.Time;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Set;

@Data
Expand All @@ -25,18 +27,19 @@ public class UserEntity extends PanacheEntityBase {
private String email;

@Column(name = "email_verified")
private LocalDateTime emailVerified;
@Temporal(TemporalType.TIMESTAMP)
private Date emailVerified;

@Column(name = "image")
private String image;

@Column(name = "password")
private String password;

@OneToMany(mappedBy = "user")
@OneToMany(mappedBy = "user", fetch = FetchType.EAGER)
private Set<AccountEntity> accounts;

@OneToMany(mappedBy = "user")
@OneToMany(mappedBy = "user", fetch = FetchType.EAGER)
private Set<SessionEntity> sessions;

public UserEntity() {
Expand Down
4 changes: 3 additions & 1 deletion server/src/main/java/dev/shiperist/model/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import dev.shiperist.entity.UserEntity;
import lombok.Data;

import java.sql.Time;
import java.time.LocalDateTime;
import java.util.Date;

@Data
public class Session {
private Long id;
private Long userId;
private String sessionToken;
private LocalDateTime expires;
private Date expires;
private UserEntity user;
}
4 changes: 3 additions & 1 deletion server/src/main/java/dev/shiperist/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
import dev.shiperist.entity.SessionEntity;
import lombok.Data;

import java.sql.Time;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Set;

@Data
public class User {
private Long id;
private String name;
private String email;
private LocalDateTime emailVerified;
private Date emailVerified;
private String image;
public String password;
private Set<AccountEntity> accounts;
Expand Down
3 changes: 2 additions & 1 deletion server/src/main/java/dev/shiperist/resource/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.ws.rs.core.Response;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.Optional;

@Path("/auth")
Expand Down Expand Up @@ -90,7 +91,7 @@ public Uni<Response> getToken(@FormParam("grant_type") String grantType,
// Assuming the refresh_token is the sessionId.
sessionService.getSession(Long.parseLong(refreshToken))
.flatMap(session -> {
if (session.isEmpty() || session.get().getExpires().isBefore(LocalDateTime.now())) {
if (session.isEmpty() || session.get().getExpires().before(new Date())) {
return Uni.createFrom().item(Response.status(Response.Status.UNAUTHORIZED)
.entity("Invalid or expired refresh token.").build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import jakarta.inject.Inject;

import java.security.Key;
import java.sql.Time;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
Expand All @@ -36,7 +37,7 @@ public Uni<Session> createSession(User user) {

session.setUserId(user.getId());
session.setSessionToken(generateSessionToken(user, expires));
session.setExpires(LocalDateTime.from(expires.toInstant()));
session.setExpires(expires);

return sessionRepository.persist(session).map(sessionMapper::toDomain);
}
Expand Down

0 comments on commit 9d13e6a

Please sign in to comment.