0.0.4
Lucia plugin for Fresh(Deno)
Repository
Current version released
2 years ago
Versions
fresh-lucia-plugin
Lucia plugin for Fresh(Deno)
Login functionality (account creation/login/logout) is provided simply by applying the plugin.
Usage
Basic
// fresh.config.ts
import { defineConfig } from "$fresh/server.ts";
import twindPlugin from "$fresh/plugins/twind.ts";
import twindConfig from "./twind.config.ts";
import { getLuciaPlugin } from "https://deno.land/x/fresh_lucia_plugin/mod.ts";
import { auth } from "./utils/lucia.ts"; // auth is lucia instance
export default defineConfig({
plugins: [
twindPlugin(twindConfig),
getLuciaPlugin(auth),
],
});No login required route.
Routes that do not require login can be defined.
// fresh.config.ts
export default defineConfig({
plugins: [
twindPlugin(twindConfig),
getLuciaPlugin(auth),{ nonAuthPaths: ["/"] }
],
});No login required route.
Can define where to redirect after logging out.
// fresh.config.ts
export default defineConfig({
plugins: [
twindPlugin(twindConfig),
getLuciaPlugin(auth),{ customLogoutAfterPath: ["/"] }
],
});Custom component
The components of the page can be replaced.
- Login route component
- Logon route component
// fresh.config.ts
export default defineConfig({
plugins: [
twindPlugin(twindConfig),
getLuciaPlugin(auth), { customLogin: { component: customLogin, path: "/login" }}
],
});Custom validate
Custom username(password) and password constraints are available.
// fresh.config.ts
import { getLuciaPlugin, type LuciaPluginTextValidateResult } from "https://deno.land/x/fresh_lucia_plugin@0.0.2/mod.ts";
function usernameValidate(username: string|undefined|null): LuciaPluginTextValidateResult {
if (!username || username.length < 10) {
return { success: false, errors: ['Username must be at least 10 characters'] };
}
return { success: true, data: username, errors: [] }
}
export default defineConfig({
plugins: [
twindPlugin(twindConfig),
getLuciaPlugin(auth, {
customUsernameValidate: usernameValidate
}
),
],
});