Skip to content

Commit

Permalink
formating
Browse files Browse the repository at this point in the history
  • Loading branch information
Octo8080X committed Jan 4, 2024
1 parent f2700a6 commit 76a2525
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,36 +62,40 @@ export default defineConfig({
```ts
import { LogoutForm } from "../../mod.ts";
import type { WithPlantation } from "../../mod.ts";
import type { PageProps} from "$fresh/server.ts";
import type { PageProps } from "$fresh/server.ts";

export default function MustLogin(props: PageProps<unknown, WithPlantation<"user">>) {
export default function MustLogin(
props: PageProps<unknown, WithPlantation<"user">>,
) {
return (
<div class="px-4 py-8 mx-auto bg-[#86efac]">
<div class="max-w-screen-md mx-auto flex flex-col items-center justify-center">
MUST LOGIN
<p>{props.state.plantation.authUserSession.resourceName} id : {props.state.plantation.authUserSession.user.userId}</p>
<p>
{props.state.plantation.authUserSession.resourceName} id :{" "}
{props.state.plantation.authUserSession.user.userId}
</p>
</div>
</div>
);
}
```

In the case of `user`, the ID of the resource can be obtained as in `props.state.plantation.authUserSession.user.userId`.
In the case of `user`, the ID of the resource can be obtained as in
`props.state.plantation.authUserSession.user.userId`.\
Similarly, the handler can also retrieve this.

```ts
```ts
export const handler = {
GET(req: Request, ctx: FreshContext<WithPlantation<"user">>){

GET(req: Request, ctx: FreshContext<WithPlantation<"user">>) {
// ex. get user id
// ctx.state.plantation.authUserSession.user.userId

return ctx.render()
}
}
return ctx.render();
},
};
```


## Custom handler and component

You can use the cli tool to build your own handlers and components.
Expand Down
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export {
passwordSchema,
usernameSchema,
} from "./src/utils/validates.ts";
export type { PlantationParams , WithPlantation } from "./types.ts";
export type { PlantationParams, WithPlantation } from "./types.ts";
export { LogoutForm } from "./src/components/LogoutForm.tsx";
20 changes: 11 additions & 9 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,18 @@ export interface DefaultActions {
};
}


type IdName<T extends string> = `${T}Id`;
type LuciaObjectKey<T extends string> = `auth${Capitalize<T>}Session`;

export interface WithPlantation<Q extends string> extends Record<string, unknown> {
plantation:{
[K in LuciaObjectKey<Q>]: {
[KK in Q]:{
[KKK in IdName<Q>]: string;
};
} & {resourceName:string}
}
export interface WithPlantation<Q extends string>
extends Record<string, unknown> {
plantation: {
[K in LuciaObjectKey<Q>]:
& {
[KK in Q]: {
[KKK in IdName<Q>]: string;
};
}
& { resourceName: string };
};
}

0 comments on commit 76a2525

Please sign in to comment.