Skip to content

Commit

Permalink
Merge pull request #4 from FuelLabs/sophie/user-session-db
Browse files Browse the repository at this point in the history
Add sql database and tables for user and session
  • Loading branch information
sdankel authored Apr 24, 2024
2 parents 60d66a6 + 059c519 commit e7056a2
Show file tree
Hide file tree
Showing 27 changed files with 668 additions and 68 deletions.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
POSTGRES_USER="postgres"
POSTGRES_PASSWORD="localpw"
POSTGRES_URI="localhost"
POSTGRES_PORT="5432"
POSTGRES_DB_NAME="forc_pub"
DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_URI}/${POSTGRES_DB_NAME}"
3 changes: 3 additions & 0 deletions .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ jobs:
with:
profile: minimal
toolchain: ${{ env.RUST_VERSION }}
- uses: docker-practice/actions-setup-docker@master
timeout-minutes: 12
- run: ./scripts/start_local_db.sh
- uses: Swatinem/rust-cache@v1
- name: Run tests
uses: actions-rs/cargo@v1
Expand Down
173 changes: 172 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name = "forc_pub"
version = "0.1.0"
edition = "2021"

[lib]
name = "forc_pub"
path = "src/lib.rs"

[dependencies]
nanoid = "0.4.0"
hex = "0.4.3"
Expand All @@ -13,3 +17,7 @@ rocket = { version = "0.5.0-rc.2", features = ["tls", "json"] }
serde = { version = "1.0", features = ["derive"] }
reqwest = { version = "0.12.2", features = ["json"] }
thiserror = "1.0.58"
diesel = { version = "2.1.6", features = ["postgres", "uuid", "r2d2"] }
dotenvy = "0.15"
uuid = "1.8.0"
diesel_migrations = "2.1.0"
1 change: 1 addition & 0 deletions app/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const SERVER_URI = process.env.REACT_APP_SERVER_URI ?? "http://localhost:8080"
8 changes: 4 additions & 4 deletions app/src/features/toolbar/components/UserButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ function UserButton() {
<StyledWrapper>
<Button color='inherit' onClick={handleMenu} endIcon={<ArrowDropDownIcon />}>
<img
src={user.avatar_url}
title={user.name}
alt={`${user.name} (TODO: login)`}
src={user.avatarUrl}
title={user.fullName}
alt={user.githubLogin}
style={{ height: '30px', width: '30px', borderRadius: '50%' }}
/>
<div style={{ marginLeft: '10px' }}>{user.name}</div>
<div style={{ marginLeft: '10px' }}>{user.fullName}</div>
</Button>
<Menu
anchorEl={anchorEl}
Expand Down
19 changes: 10 additions & 9 deletions app/src/features/toolbar/hooks/useGithubAuth.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { useCallback, useEffect, useState } from 'react';
import { useSearchParams } from 'react-router-dom';
import { useLocalSession } from '../../../utils/localStorage';
import { SERVER_URI } from '../../../constants';

interface AuthenticatedUser {
avatar_url?: string;
name: string;
fullName: string;
email?: string;
githubUrl: string;
githubLogin: string;
isAdmin: boolean;
avatarUrl?: string;
}

interface LoginResponse {
Expand Down Expand Up @@ -54,7 +58,7 @@ export function useGithubAuth(): [AuthenticatedUser | null, () => void] {
const params = {
code: githubCode,
};
const request = new Request('http://localhost:8080/login', {
const request = new Request(`${SERVER_URI}/login`, {
method: 'POST',
body: JSON.stringify(params),
});
Expand Down Expand Up @@ -93,12 +97,9 @@ export function useGithubAuth(): [AuthenticatedUser | null, () => void] {
return;
}

const request = new Request(
`http://localhost:8080/session?id=${sessionId}`,
{
method: 'GET',
}
);
const request = new Request(`${SERVER_URI}/session?id=${sessionId}`, {
method: 'GET',
});
fetch(request)
.then((response) => {
if (response.status < 400) {
Expand Down
7 changes: 7 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[target.aarch64-apple-darwin]
rustflags = [
'-L',
'/opt/homebrew/opt/libpq/lib',
'-L',
'/opt/homebrew/lib'
]
9 changes: 9 additions & 0 deletions diesel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# For documentation on how to configure this file,
# see https://diesel.rs/guides/configuring-diesel-cli

[print_schema]
file = "src/schema.rs"
custom_type_derives = ["diesel::query_builder::QueryId"]

[migrations_directory]
dir = "migrations"
Empty file added migrations/.keep
Empty file.
6 changes: 6 additions & 0 deletions migrations/00000000000000_diesel_initial_setup/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.

DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
DROP FUNCTION IF EXISTS diesel_set_updated_at();
Loading

0 comments on commit e7056a2

Please sign in to comment.