Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tschuehly committed Jun 12, 2024
1 parent a8a9566 commit d188965
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package de.tschuehly.htmx.spring.supabase.auth
import com.auth0.jwt.JWT
import com.auth0.jwt.JWTVerifier
import com.auth0.jwt.algorithms.Algorithm
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import de.tschuehly.htmx.spring.supabase.auth.config.DefaultExceptionHandlerConfig
import de.tschuehly.htmx.spring.supabase.auth.config.SupabaseProperties
Expand All @@ -20,14 +21,12 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.jdbc.DataSourceBuilder
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import
import org.springframework.context.annotation.Primary
import java.util.*
import javax.sql.DataSource


Expand Down Expand Up @@ -80,4 +79,28 @@ class SupabaseAutoConfiguration(
return JWT.require(Algorithm.HMAC256(supabaseProperties.jwtSecret)).build()
}


@Bean
@ConditionalOnProperty(prefix = "supabase.database", name = ["host"])
fun dataSource(
supabaseProperties: SupabaseProperties,
): DataSource {
val properties = Properties()
properties.setProperty("maximumPoolSize", "20")
properties.setProperty("minimumIdle", "15")

properties.setProperty("driverClassName", "org.postgresql.Driver");
supabaseProperties.database?.let { db ->
db.username?.let {
properties.setProperty("username", it);
} ?: let {
properties.setProperty("username", "postgres.${supabaseProperties.projectId}")
}
properties.setProperty("jdbcUrl","jdbc:postgresql://${db.host}:${db.port}/${db.name}")
properties.setProperty("password", db.password);
}

val config = HikariConfig(properties)
return HikariDataSource(config)
}
}

0 comments on commit d188965

Please sign in to comment.