generated from phundrak/rust-poem-openapi-template
feat: authentication through Discord OAuth2
This commit is contained in:
parent
1125bc4a38
commit
ff90b1959f
5
migrations/20240809173617_users.down.sql
Normal file
5
migrations/20240809173617_users.down.sql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
-- Add down migration script here
|
||||||
|
ALTER TABLE IF EXISTS public.sessions DROP CONSTRAINT IF EXISTS sessions_user_id_users_fk;
|
||||||
|
DROP TABLE IF EXISTS public.sessions;
|
||||||
|
DROP TABLE IF EXISTS public.users;
|
||||||
|
DROP EXTENSION IF EXISTS "uuid-ossp";
|
29
migrations/20240809173617_users.up.sql
Normal file
29
migrations/20240809173617_users.up.sql
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
-- Add up migration script here
|
||||||
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS public.users
|
||||||
|
(
|
||||||
|
id uuid NOT NULL DEFAULT uuid_generate_v4(),
|
||||||
|
email character varying(255) NOT NULL,
|
||||||
|
created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
last_updated timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
CONSTRAINT users_email_unique UNIQUE (email)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS public.sessions
|
||||||
|
(
|
||||||
|
id uuid NOT NULL DEFAULT uuid_generate_v4(),
|
||||||
|
user_id uuid NOT NULL,
|
||||||
|
session_id character varying NOT NULL,
|
||||||
|
expires_at timestamp with time zone NOT NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
CONSTRAINT sessions_user_id_unique UNIQUE (user_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.sessions
|
||||||
|
ADD CONSTRAINT sessions_user_id_users_fk FOREIGN KEY (user_id)
|
||||||
|
REFERENCES public.users (id) MATCH SIMPLE
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE
|
||||||
|
NOT VALID;
|
@ -16,3 +16,7 @@ email:
|
|||||||
user: user@gege-jdr-backend.example
|
user: user@gege-jdr-backend.example
|
||||||
from: GegeJdrBackend <noreply@gege-jdr-backend.example>
|
from: GegeJdrBackend <noreply@gege-jdr-backend.example>
|
||||||
password: hunter2
|
password: hunter2
|
||||||
|
|
||||||
|
discord:
|
||||||
|
client_id: changeme
|
||||||
|
client_secret: changeme
|
||||||
|
@ -4,6 +4,7 @@ use sqlx::ConnectOptions;
|
|||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub application: ApplicationSettings,
|
pub application: ApplicationSettings,
|
||||||
pub database: Database,
|
pub database: Database,
|
||||||
|
pub discord: Discord,
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
pub email: EmailSettings,
|
pub email: EmailSettings,
|
||||||
pub frontend_url: String,
|
pub frontend_url: String,
|
||||||
@ -164,6 +165,12 @@ pub struct EmailSettings {
|
|||||||
pub from: String,
|
pub from: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, serde::Deserialize, Clone, Default)]
|
||||||
|
pub struct Discord {
|
||||||
|
client_id: String,
|
||||||
|
client_secret: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
Loading…
Reference in New Issue
Block a user