feat: add authentication
This commit is contained in:
@ -2,6 +2,7 @@ import { Menu } from "@islands/KMenu/types.ts";
|
||||
import { addMovieInfos } from "@islands/KMenu/commands/add_movie_infos.ts";
|
||||
import { createNewMovie } from "@islands/KMenu/commands/create_movie.ts";
|
||||
import { createNewArticle } from "@islands/KMenu/commands/create_article.ts";
|
||||
import { getCookie } from "@lib/string.ts";
|
||||
|
||||
export const menus: Record<string, Menu> = {
|
||||
main: {
|
||||
@ -18,6 +19,30 @@ export const menus: Record<string, Menu> = {
|
||||
state.activeState.value = "normal";
|
||||
state.visible.value = false;
|
||||
},
|
||||
visible: () => {
|
||||
if (!getCookie("session_cookie")) return false;
|
||||
return true;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Login",
|
||||
icon: "IconLogin",
|
||||
cb: () => {
|
||||
window.location.pathname = "/api/auth/login";
|
||||
},
|
||||
visible: () => {
|
||||
return !getCookie("session_cookie");
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Logout",
|
||||
icon: "IconLogout",
|
||||
cb: () => {
|
||||
window.location.pathname = "/api/auth/logout";
|
||||
},
|
||||
visible: () => {
|
||||
return !!getCookie("session_cookie");
|
||||
},
|
||||
},
|
||||
createNewArticle,
|
||||
createNewMovie,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { MenuEntry } from "@islands/KMenu/types.ts";
|
||||
import { Movie } from "@lib/resource/movies.ts";
|
||||
import { TMDBMovie } from "@lib/types.ts";
|
||||
import { getCookie } from "@lib/string.ts";
|
||||
|
||||
export const addMovieInfos: MenuEntry = {
|
||||
title: "Add Movie infos",
|
||||
@ -43,6 +44,7 @@ export const addMovieInfos: MenuEntry = {
|
||||
},
|
||||
visible: () => {
|
||||
const loc = globalThis["location"];
|
||||
if (!getCookie("session_cookie")) return false;
|
||||
return loc?.pathname?.includes("movie");
|
||||
},
|
||||
};
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { MenuEntry } from "@islands/KMenu/types.ts";
|
||||
import { fetchStream, isValidUrl } from "@lib/helpers.ts";
|
||||
import { getCookie } from "@lib/string.ts";
|
||||
|
||||
export const createNewArticle: MenuEntry = {
|
||||
title: "Create new article",
|
||||
@ -35,5 +36,8 @@ export const createNewArticle: MenuEntry = {
|
||||
}
|
||||
});
|
||||
},
|
||||
visible: () => true,
|
||||
visible: () => {
|
||||
if (!getCookie("session_cookie")) return false;
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
@ -2,6 +2,7 @@ import { MenuEntry } from "@islands/KMenu/types.ts";
|
||||
import { TMDBMovie } from "@lib/types.ts";
|
||||
import { debounce } from "@lib/helpers.ts";
|
||||
import { Movie } from "@lib/resource/movies.ts";
|
||||
import { getCookie } from "@lib/string.ts";
|
||||
|
||||
export const createNewMovie: MenuEntry = {
|
||||
title: "Create new movie",
|
||||
@ -40,8 +41,6 @@ export const createNewMovie: MenuEntry = {
|
||||
|
||||
const movies = await response.json() as TMDBMovie[];
|
||||
|
||||
console.log({ query, currentQuery, movies });
|
||||
|
||||
if (query !== currentQuery) return;
|
||||
|
||||
state.menus["input_link"] = {
|
||||
@ -55,6 +54,7 @@ export const createNewMovie: MenuEntry = {
|
||||
method: "POST",
|
||||
});
|
||||
const movie = await response.json() as Movie;
|
||||
unsub();
|
||||
window.location.href = "/movies/" + movie.name;
|
||||
},
|
||||
};
|
||||
@ -68,5 +68,8 @@ export const createNewMovie: MenuEntry = {
|
||||
search(value);
|
||||
});
|
||||
},
|
||||
visible: () => true,
|
||||
visible: () => {
|
||||
if (!getCookie("session_cookie")) return false;
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user