-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add tabs in docs for dev, ui, guides
- Loading branch information
1 parent
7dc36cf
commit 8731d8d
Showing
31 changed files
with
449 additions
and
225 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function Page() { | ||
return ( | ||
<div> | ||
<h1>Page</h1> | ||
<p>This is a page.</p> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface Props { | ||
children: React.ReactNode; | ||
} | ||
|
||
export default function Layout({ children }: Props) { | ||
return <div>{children}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use client'; | ||
|
||
import { cn } from '@/utils/classnames'; | ||
import { useParams } from 'next/navigation'; | ||
import { ReactNode } from 'react'; | ||
|
||
export function useMode(): string | undefined { | ||
const { slug } = useParams(); | ||
return Array.isArray(slug) && slug.length > 0 ? slug[0] : undefined; | ||
} | ||
|
||
export function Body({ | ||
children, | ||
}: { | ||
children: ReactNode; | ||
}): React.ReactElement { | ||
const mode = useMode(); | ||
|
||
return ( | ||
<body className={cn(mode, 'flex min-h-screen flex-col')}>{children}</body> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import { RootProvider } from 'fumadocs-ui/provider'; | ||
import { GeistSans } from 'geist/font/sans'; | ||
import type { ReactNode } from 'react'; | ||
import { Body } from '@/app/layout.client'; | ||
import './global.css'; | ||
|
||
export default function Layout({ children }: { children: ReactNode }) { | ||
return ( | ||
<html lang="en" className={GeistSans.className} suppressHydrationWarning> | ||
<body> | ||
<Body> | ||
<RootProvider>{children}</RootProvider> | ||
</body> | ||
</Body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { LucideIcon } from 'lucide-react'; | ||
import { TerminalIcon } from 'lucide-react'; | ||
|
||
export function create({ | ||
icon: Icon, | ||
}: { | ||
icon?: LucideIcon; | ||
}): React.ReactElement { | ||
return ( | ||
<div className="from-secondary rounded-md border bg-gradient-to-b p-1 shadow-sm"> | ||
{Icon ? <Icon /> : <TerminalIcon />} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
--- | ||
title: Authorization | ||
description: How to protect routes with authorization. | ||
--- | ||
|
||
## Backend | ||
|
||
We're implementing a custom authorization system, which gives us more flexibility and control over the authorization process. Our system use [Guards](https://docs.nestjs.com/guards) from NestJS to protect routes. | ||
|
||
### Portected route | ||
|
||
To protect a route _(required sign in user)_, you need to add the `@UseGuards(AuthGuards)` decorator to the route. | ||
|
||
```ts title="show.resolver.ts" | ||
import { Args, Query, Resolver } from '@nestjs/graphql'; | ||
import { UseGuards } from '@nestjs/common'; | ||
import { AuthGuards } from 'vitnode-backend'; // [!code highlight] | ||
|
||
import { ShowCoreMembersService } from './show.service'; | ||
import { ShowCoreMembersObj } from './dto/show.obj'; | ||
|
||
@Resolver() | ||
export class ShowCoreMembersResolver { | ||
constructor(private readonly service: ShowCoreMembersService) {} | ||
|
||
@UseGuards(AuthGuards) // [!code highlight] | ||
@Query(() => ShowCoreMembersObj) | ||
async core_members__show(): Promise<ShowCoreMembersObj> { | ||
return this.service.show(); | ||
} | ||
} | ||
``` | ||
|
||
#### Admin protected route | ||
|
||
To protect a route with `admin` permissions, you need to use the `@UseGuards(AdminAuthGuards)` decorator. | ||
|
||
```ts title="show.resolver.ts" | ||
import { Args, Query, Resolver } from '@nestjs/graphql'; | ||
import { UseGuards } from '@nestjs/common'; | ||
import { AdminAuthGuards } from 'vitnode-backend'; // [!code highlight] | ||
|
||
import { ShowCoreMembersService } from './show.service'; | ||
import { ShowCoreMembersObj } from './dto/show.obj'; | ||
|
||
@Resolver() | ||
export class ShowCoreMembersResolver { | ||
constructor(private readonly service: ShowCoreMembersService) {} | ||
|
||
@UseGuards(AdminAuthGuards) // [!code highlight] | ||
@Query(() => ShowCoreMembersObj) | ||
async core_members__show(): Promise<ShowCoreMembersObj> { | ||
return this.service.show(); | ||
} | ||
} | ||
``` | ||
|
||
### Current user data | ||
|
||
Whan you are using `@UseGuards(AuthGuards)` or `@UseGuards(AdminAuthGuards)` you can access to the current user in the resolver by using the `@CurrentUser()` decorator as param route. | ||
|
||
```ts title="show.resolver.ts" | ||
import { Args, Query, Resolver } from '@nestjs/graphql'; | ||
import { UseGuards } from '@nestjs/common'; | ||
import { AuthGuards, CurrentUser, User } from 'vitnode-backend'; // [!code highlight] | ||
|
||
import { ShowCoreMembersService } from './show.service'; | ||
import { ShowCoreMembersObj } from './dto/show.obj'; | ||
|
||
@Resolver() | ||
export class ShowCoreMembersResolver { | ||
constructor(private readonly service: ShowCoreMembersService) {} | ||
|
||
@UseGuards(AuthGuards) | ||
@Query(() => ShowCoreMembersObj) | ||
async core_members__show( | ||
@CurrentUser() user: User, // [!code highlight] | ||
): Promise<ShowCoreMembersObj> { | ||
return this.service.show(user); | ||
} | ||
} | ||
``` | ||
|
||
### Current user data without protected route | ||
|
||
If you need to access to the current user in a route you need use the `@OptionalAuth()` decorator in route. You need change `@CurrentUser()` decorator to optional param route. | ||
|
||
```ts title="show.resolver.ts" | ||
import { Args, Query, Resolver } from '@nestjs/graphql'; | ||
import { UseGuards } from '@nestjs/common'; | ||
import { AuthGuards, CurrentUser, User, OptionalAuth } from 'vitnode-backend'; // [!code highlight] | ||
|
||
import { ShowCoreMembersService } from './show.service'; | ||
import { ShowCoreMembersObj } from './dto/show.obj'; | ||
|
||
@Resolver() | ||
export class ShowCoreMembersResolver { | ||
constructor(private readonly service: ShowCoreMembersService) {} | ||
|
||
@OptionalAuth() // [!code highlight] | ||
@UseGuards(AuthGuards) | ||
@Query(() => ShowCoreMembersObj) | ||
async core_members__show( | ||
@CurrentUser() user: User, | ||
): Promise<ShowCoreMembersObj> { | ||
return this.service.show(user); | ||
} | ||
} | ||
``` | ||
|
||
## Frontend | ||
|
||
TODO: Add frontend authorization docs |
Oops, something went wrong.