Skip to content

Commit

Permalink
Working Google login
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Nov 30, 2024
1 parent e88f4bd commit c529705
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ Learn programming by thinking.

You need to have a PostgreSQL database.

```
```zshrc
brew install postgresql
brew services start postgresql@14
psql -U postgres -c "CREATE DATABASE ivy_learn;"
psql -d ivy_learn -c "CREATE USER postgres WITH PASSWORD 'password';"
psql -d ivy_learn -c "ALTER USER postgres WITH SUPERUSER;"
```

**(optional) Drop local database:**

```zshrc
psql -U postgres -c "DROP DATABASE ivy_learn;"
psql -U postgres -c "CREATE DATABASE ivy_learn;"
```

**Environment Variables**

```zshrc
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/kotlin/ivy/learn/api/common/ApiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ suspend inline fun RoutingContext.handleRequest(
handler(call)
}
} catch (e: Throwable) {
Either.Left(ServerError.Unknown("Unexpected error occurred: $e"))
Either.Left(ServerError.Unknown("Unexpected error occurred."))
}
result.onLeft { error ->
respondError(error)
Expand Down
8 changes: 7 additions & 1 deletion server/src/main/kotlin/ivy/learn/data/database/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import arrow.core.raise.catch
import arrow.core.raise.either
import ivy.learn.config.DatabaseConfig
import ivy.learn.data.database.tables.Analytics
import ivy.learn.data.database.tables.Sessions
import ivy.learn.data.database.tables.Users
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
Expand All @@ -30,7 +32,11 @@ class Database {

private fun createDbSchema(database: Database): Either<Throwable, Database> = catch({
transaction {
SchemaUtils.create(Analytics)
SchemaUtils.create(
Users,
Sessions,
Analytics,
)
}
Either.Right(database)
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.jetbrains.exposed.sql.kotlin.datetime.timestamp

object Sessions : Table() {
val token = varchar("token", length = 128).uniqueIndex()
val userId = Analytics.reference(
val userId = reference(
name = "user_id",
refColumn = Users.id,
onDelete = ReferenceOption.CASCADE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import io.ktor.http.*
import ivy.learn.config.ServerConfiguration
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.slf4j.Logger

class GoogleOAuthUseCase(
private val config: ServerConfiguration,
private val httpClient: HttpClient,
private val logger: Logger,
) {

suspend fun verify(
Expand All @@ -29,7 +31,9 @@ class GoogleOAuthUseCase(
email = userInfoResponse.email,
names = userInfoResponse.name,
profilePictureUrl = userInfoResponse.picture,
)
).also {

}
}

/*
Expand Down

0 comments on commit c529705

Please sign in to comment.