Compare commits

..

No commits in common. "5a3a25982c000e24375a25f38b44a5467bdef2ac" and "1447509699f8299468eee270464be4ec7a4b634b" have entirely different histories.

8 changed files with 24 additions and 188 deletions

View File

@ -9,7 +9,6 @@
"version": "0.0.0", "version": "0.0.0",
"dependencies": { "dependencies": {
"autoprefixer": "^10.4.18", "autoprefixer": "^10.4.18",
"axios": "^1.6.8",
"postcss": "^8.4.35", "postcss": "^8.4.35",
"tailwindcss": "^3.4.1", "tailwindcss": "^3.4.1",
"vue": "^3.3.11", "vue": "^3.3.11",
@ -1420,11 +1419,6 @@
"resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz", "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz",
"integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==" "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg=="
}, },
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"node_modules/autoprefixer": { "node_modules/autoprefixer": {
"version": "10.4.18", "version": "10.4.18",
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.18.tgz", "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.18.tgz",
@ -1461,16 +1455,6 @@
"postcss": "^8.1.0" "postcss": "^8.1.0"
} }
}, },
"node_modules/axios": {
"version": "1.6.8",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz",
"integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/balanced-match": { "node_modules/balanced-match": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@ -1636,17 +1620,6 @@
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"dev": true "dev": true
}, },
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/commander": { "node_modules/commander": {
"version": "4.1.1", "version": "4.1.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
@ -1719,14 +1692,6 @@
} }
} }
}, },
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/didyoumean": { "node_modules/didyoumean": {
"version": "1.2.2", "version": "1.2.2",
"resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz", "resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz",
@ -1868,25 +1833,6 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/follow-redirects": {
"version": "1.15.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/foreground-child": { "node_modules/foreground-child": {
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz",
@ -1902,19 +1848,6 @@
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
} }
}, },
"node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/fraction.js": { "node_modules/fraction.js": {
"version": "4.3.7", "version": "4.3.7",
"resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.3.7.tgz", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.3.7.tgz",
@ -2227,25 +2160,6 @@
"node": ">=8.6" "node": ">=8.6"
} }
}, },
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/minimatch": { "node_modules/minimatch": {
"version": "9.0.3", "version": "9.0.3",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz",
@ -2617,11 +2531,6 @@
"resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz", "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz",
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==" "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ=="
}, },
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"node_modules/queue-microtask": { "node_modules/queue-microtask": {
"version": "1.2.3", "version": "1.2.3",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",

View File

@ -12,7 +12,6 @@
}, },
"dependencies": { "dependencies": {
"autoprefixer": "^10.4.18", "autoprefixer": "^10.4.18",
"axios": "^1.6.8",
"postcss": "^8.4.35", "postcss": "^8.4.35",
"tailwindcss": "^3.4.1", "tailwindcss": "^3.4.1",
"vue": "^3.3.11", "vue": "^3.3.11",

View File

@ -1,37 +1,23 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue';
import router from '@/router';
const email = defineModel("email"); const email = defineModel("email");
const password = defineModel("password"); const password = defineModel("password");
const errorMessage = ref(null);
async function login() { async function login() {
await fetch(import.meta.hot ? "http://localhost:54600/api/v1/login_user" : "/api/v1/login_user", { const response = await fetch(
method: "POST", "http://0.0.0.0:54600/api/v1/login_user",
headers: { {
"Content-Type": "application/json", method: "POST",
//"Access-Control-Allow-Origin": "*" headers: {
}, "Content-Type": "application/json",
credentials: "include", },
//mode: "cors", credentials: "include",
body: JSON.stringify({ email: email.value, password: password.value }) mode: "cors",
}) body: JSON.stringify({ email: email.value, password: password.value })
.then(async response => { }
//const isJson = response.headers.get('content-type')?.includes('application/json'); );
const data = await response.json();
if (!response.ok) { let { status, token } = await response.json();
const error = (data && data.message) || response.status; console.log(status);
return Promise.reject(error);
}
router.push({ path: '/me' });
})
.catch(error => {
errorMessage.value = error;
console.error(error);
});
}; };
</script> </script>
@ -55,7 +41,5 @@ async function login() {
In</button> In</button>
</div> </div>
</form> </form>
<p v-if="errorMessage" class="text-center pt-3 pb-3 bg-orange-900 rounded border border-orange-700">{{
errorMessage }}</p>
</div> </div>
</template> </template>

View File

@ -4,8 +4,6 @@ import router from '@/router';
import '@/assets/style.css'; import '@/assets/style.css';
import Me from '@/views/Me.vue'
import Home from '@/views/Home.vue'
createApp(App) createApp(App)
.use(router) .use(router)
.mount('#app'); .mount('#app');

View File

@ -4,8 +4,7 @@ const router = createRouter({
history: createWebHistory(), history: createWebHistory(),
routes: [ routes: [
{ path: '/', component: () => import('./views/Home.vue') }, { path: '/', component: () => import('./views/Home.vue') },
{ path: '/user/login', component: () => import('./views/SignIn.vue') }, { path: '/user/login', component: () => import('./views/SignIn.vue') }
{ path: '/me', component: () => import('./views/Me.vue') }
] ]
}); });

View File

@ -1,48 +0,0 @@
<script setup lang="ts">
import Base from '@/views/Base.vue';
import { ref, onMounted } from 'vue';
import axios from 'axios';
const email = ref(null);
const name = ref(null);
const is_admin = ref(null);
const errorMessage = ref(null);
onMounted(async () => {
const asd = await fetch(import.meta.hot ? "http://localhost:54600/api/v1/me" : "/api/v1/me", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
mode: "cors",
})
.then(async response => {
const isJson = response.headers.get('content-type')?.includes('application/json');
const data = isJson && await response.json();
if (!response.ok) {
const error = (data && data.message) || response.status;
return Promise.reject(error);
}
name.value = data.data.user.name;
email.value = data.data.user.email;
is_admin.value = data.data.user.is_admin;
})
.catch(error => {
errorMessage.value = error;
console.error("Error occured:", error);
});
})
</script>
<template>
<Base>
<p v-if="errorMessage" class="text-center pt-3 pb-3 bg-orange-900 rounded border border-orange-700">{{
errorMessage }}</p>
<p>{{ name }}</p>
<p>{{ email }}</p>
<p>{{ is_admin }}</p>
</Base>
</template>

View File

@ -46,7 +46,7 @@ impl Config {
name: env::var("DATABASE_NAME").unwrap_or("elnafo".to_string()), name: env::var("DATABASE_NAME").unwrap_or("elnafo".to_string()),
}, },
server: Server { server: Server {
address: env::var("SERVER_ADDRESS").unwrap_or("127.0.0.1".to_string()), address: env::var("SERVER_ADDRESS").unwrap_or("0.0.0.0".to_string()),
port: env::var("SERVER_PORT") port: env::var("SERVER_PORT")
.unwrap_or("54600".to_string()) .unwrap_or("54600".to_string())
.parse() .parse()

View File

@ -5,9 +5,9 @@ pub mod error_handle;
pub mod state; pub mod state;
use axum::{ use axum::{
extract::{Path, State}, extract::State,
http::{ http::{
header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE, COOKIE, ORIGIN}, header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE, ORIGIN},
HeaderValue, Method, StatusCode, Uri, HeaderValue, Method, StatusCode, Uri,
}, },
middleware, middleware,
@ -65,11 +65,8 @@ async fn main() {
let cors = CorsLayer::new() let cors = CorsLayer::new()
.allow_methods([Method::GET, Method::POST, Method::OPTIONS]) .allow_methods([Method::GET, Method::POST, Method::OPTIONS])
.allow_headers(vec![ORIGIN, AUTHORIZATION, ACCEPT, CONTENT_TYPE, COOKIE]) .allow_headers(vec![ORIGIN, AUTHORIZATION, ACCEPT, CONTENT_TYPE])
.allow_origin([ .allow_origin("http://0.0.0.0:54600".parse::<HeaderValue>().unwrap()) //Any)
"http://localhost:54600".parse().unwrap(),
"http://localhost:5173".parse().unwrap(),
]) //Any)
.allow_credentials(true); //"http://localhost:5173".parse::<HeaderValue>().unwrap()); .allow_credentials(true); //"http://localhost:5173".parse::<HeaderValue>().unwrap());
let app = Router::new() let app = Router::new()
@ -78,6 +75,10 @@ async fn main() {
.route("/assets/*file", get(static_handler)) .route("/assets/*file", get(static_handler))
.route("/api/v1/register_user", post(api::v1::register_user)) .route("/api/v1/register_user", post(api::v1::register_user))
.route("/api/v1/login_user", post(api::v1::login_user)) .route("/api/v1/login_user", post(api::v1::login_user))
.layer(cors)
.route("/api/v1/healthcheck", get(api::v1::healthcheck))
.route("/api/v1/users", get(users))
.route("/api/v1/logout_user", get(api::v1::logout_user))
.route( .route(
"/api/v1/me", "/api/v1/me",
get(api::v1::me).route_layer(middleware::from_fn_with_state( get(api::v1::me).route_layer(middleware::from_fn_with_state(
@ -85,10 +86,6 @@ async fn main() {
api::v1::jwt_auth, api::v1::jwt_auth,
)), )),
) )
.layer(cors)
.route("/api/v1/healthcheck", get(api::v1::healthcheck))
.route("/api/v1/users", get(users))
.route("/api/v1/logout_user", get(api::v1::logout_user))
.layer( .layer(
TraceLayer::new_for_http() TraceLayer::new_for_http()
.make_span_with(trace::DefaultMakeSpan::new().level(Level::INFO)) .make_span_with(trace::DefaultMakeSpan::new().level(Level::INFO))
@ -112,8 +109,6 @@ async fn user_login() -> impl IntoResponse {
frontend::BaseTemplate { view: "signin" } frontend::BaseTemplate { view: "signin" }
} }
async fn user(Path(user): Path<String>) -> impl IntoResponse {}
async fn users( async fn users(
State(state): State<Arc<AppState>>, State(state): State<Arc<AppState>>,
) -> Result<Json<Vec<User>>, (StatusCode, Json<serde_json::Value>)> { ) -> Result<Json<Vec<User>>, (StatusCode, Json<serde_json::Value>)> {