Skip to content

Xuhv/kf-fresh-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@kf/fresh-auth

Policies-based authentication for Fresh.

usage

  1. create a middleware to add user information to the context
const authMiddleware = createAuthMiddleware<string, string>(async (ctx) => {
  const accessToken = ctx.req.headers.get("Authorization")?.slice(7);
  if (!accessToken) return undefined;

  const { error, result } = await mightFail(verifyToken(accessToken))
  return error ? undefined : { id: result.payload.sub!, policies: result.payload.policies as string[] };
});
  1. create a handler with policies
app.get("/user", defineHandler((ctx) => {
  return new Response(`Here is ${getAuthInfo(ctx)?.id}.`)
}, ["user"]) as MiddlewareFn<unknown>);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published