Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/authorization #31

Merged
merged 88 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
64d494a
feat: authorizatoin
kirill-ivanovvv Jun 19, 2024
57cecce
fix: yarn check
kirill-ivanovvv Jun 19, 2024
1052420
fix: delete unused
kirill-ivanovvv Jun 20, 2024
119fd73
fix(registration.fragment): moved out constants and hooks
kirill-ivanovvv Jun 20, 2024
8c5247a
fix(registration-endpoint): mode endpoint from api to page dir
kirill-ivanovvv Jun 20, 2024
09df48c
fix: remove unused deps
kirill-ivanovvv Jun 20, 2024
0b133fe
fix(registration.page): split component into client and server
kirill-ivanovvv Jun 20, 2024
bf7e6db
yarn check
kirill-ivanovvv Jun 20, 2024
5e66d8d
master merge
kirill-ivanovvv Jun 20, 2024
105b46b
feat: add env
kirill-ivanovvv Jun 20, 2024
686f7c7
fix(env): move env check to the top
kirill-ivanovvv Jun 20, 2024
d33e4cb
yarn
kirill-ivanovvv Jun 20, 2024
0019b0f
feat(package.json): add globals directory
kirill-ivanovvv Jun 20, 2024
3b1ba8b
feat(globals/data): get github access tokken func
kirill-ivanovvv Jun 20, 2024
908897a
fix(registration.server): write gh tokkent to cookies
kirill-ivanovvv Jun 20, 2024
151a68b
fix(base-layout): devide component to server and client parts
kirill-ivanovvv Jun 20, 2024
231f10e
fix(add-member-to-org): locales fix
kirill-ivanovvv Jun 21, 2024
2ddd900
fix(base-layout): dark-theme fix
kirill-ivanovvv Jun 21, 2024
cdd526e
fix(registration.server): move octokit auth func from @globals to reg…
kirill-ivanovvv Jun 21, 2024
d26b860
feat(entrypoint): additional env check
kirill-ivanovvv Jun 21, 2024
7d2803c
refactor(registration.server): refactor
kirill-ivanovvv Jun 21, 2024
6ac6c91
yarn
kirill-ivanovvv Jun 21, 2024
9dbe758
fix(package.json): delete unused
kirill-ivanovvv Jun 21, 2024
4b92ca5
draft: authorization; scopes
kirill-ivanovvv Jun 21, 2024
af273dd
feat: authentificated as app on root server layout
kirill-ivanovvv Jun 21, 2024
52619e1
feat(base-layout-data): get data, what base layout needed
kirill-ivanovvv Jun 21, 2024
033cbd2
feat(locales): move locales to @global
kirill-ivanovvv Jun 21, 2024
464a054
yarn
kirill-ivanovvv Jun 21, 2024
c20e03b
feat(endpoints): create workspace
kirill-ivanovvv Jun 21, 2024
0cbce12
feat(gh-server-app): create server-component
kirill-ivanovvv Jun 21, 2024
942f81a
feat(globals): add private utils func
kirill-ivanovvv Jun 21, 2024
6d61839
feat(globals): add utils functions
kirill-ivanovvv Jun 21, 2024
31e1a5f
yarn
kirill-ivanovvv Jun 21, 2024
e7ad61f
fix(globals): remove privates
kirill-ivanovvv Jun 21, 2024
0404cc7
fix(gh-app-server-component): fix private key auth method
kirill-ivanovvv Jun 21, 2024
fa0e125
fix(root-layout): divided into 2 components
kirill-ivanovvv Jun 21, 2024
c71683c
fix(registration-fragment): moves endpoint function to endpoint
kirill-ivanovvv Jun 21, 2024
d097ecb
feat(api): endpoint provide; change route after success auth
kirill-ivanovvv Jun 21, 2024
6ad63f0
fix(root-layout): moves all logic to fragment
kirill-ivanovvv Jun 21, 2024
d08f395
fix: some service changes
kirill-ivanovvv Jun 21, 2024
087e586
feat(base-layout): render authed user data on cli
kirill-ivanovvv Jun 21, 2024
a099162
yarn
kirill-ivanovvv Jun 22, 2024
3754695
feat(globals.data): graphql codegen
kirill-ivanovvv Jun 22, 2024
db432d8
fix(base-layout): move data logic to globals data
kirill-ivanovvv Jun 22, 2024
9c540df
fix(globals.data): fix data generation; query suntax fixes
kirill-ivanovvv Jun 22, 2024
ce8b6ca
feat(middleware): check token cookie&redirect
kirill-ivanovvv Jun 22, 2024
9c2f546
feat(base-layout): redirect on cookie expires
kirill-ivanovvv Jun 22, 2024
0437157
fix(root-layout): remove GH server app
kirill-ivanovvv Jun 22, 2024
f378ca3
feat(endpoint): add constants
kirill-ivanovvv Jun 22, 2024
73a5a37
fix(gh-server-app): remove
kirill-ivanovvv Jun 22, 2024
0e79707
feat: logout
kirill-ivanovvv Jun 22, 2024
90cc70e
feat(sidebar): render open state without items
kirill-ivanovvv Jun 22, 2024
1e47159
yarn
kirill-ivanovvv Jun 22, 2024
6575a47
fix(base-layout): height fix
kirill-ivanovvv Jun 22, 2024
0ef2946
fix: yarn check
kirill-ivanovvv Jun 23, 2024
58002d3
fix: move locals to global
kirill-ivanovvv Jun 23, 2024
89d3cdb
feat: layout
kirill-ivanovvv Jun 24, 2024
79a28a1
feat: animations
kirill-ivanovvv Jun 24, 2024
907a7a4
refactor: devided into interfaces and styles
kirill-ivanovvv Jun 24, 2024
456d3b0
chore: feat/authrorization merge
kirill-ivanovvv Jun 24, 2024
a527b80
chore: yarn check
kirill-ivanovvv Jun 24, 2024
6d7ccc6
fix: review changes
kirill-ivanovvv Jun 25, 2024
c56e5f7
feat(base-layout): get gh url from query
kirill-ivanovvv Jun 25, 2024
427a8cb
feat(icons): add colors props; logo default colors and color props
kirill-ivanovvv Jun 25, 2024
a77db0a
feat(logo): add logo dard variant
kirill-ivanovvv Jun 25, 2024
e55bbf2
feat(sidebar): dark theme; and redirect to viewer gh page
kirill-ivanovvv Jun 25, 2024
48660d3
feat(base-layout): add profile url to query; update graph ql codegen
kirill-ivanovvv Jun 25, 2024
6841e2d
yarn
kirill-ivanovvv Jun 25, 2024
7c93598
feat(yarnrc): added missing dependencies
kirill-ivanovvv Jun 25, 2024
b0bf756
feat(atls-logo): active theme props
kirill-ivanovvv Jun 25, 2024
87df5f9
fix: yarn check fixes
kirill-ivanovvv Jun 25, 2024
0f8e11c
refactor: small review changes
kirill-ivanovvv Jun 26, 2024
bdfb6ce
fix: gql codegen interface fix
kirill-ivanovvv Jun 26, 2024
a039037
fix: query props fixes
kirill-ivanovvv Jun 26, 2024
e09bd30
yarn
kirill-ivanovvv Jun 28, 2024
d58c974
fix: change octokit auth interface to fetch; change auth as oAuthApp …
kirill-ivanovvv Jun 28, 2024
78e6b88
refactor(token): add cookie name to env
kirill-ivanovvv Jul 1, 2024
f684c29
refactor(get-gh-auth-token): change names
kirill-ivanovvv Jul 1, 2024
b0798a7
refactor(check-envs): change func; moved required vars to consts file
kirill-ivanovvv Jul 1, 2024
70a96e1
refactor(api): namings; throw error
kirill-ivanovvv Jul 1, 2024
22c5fa5
fix(registration): auth hook
kirill-ivanovvv Jul 1, 2024
bfd5d9f
feat(root-layout): render error message; client hook for get error me…
kirill-ivanovvv Jul 1, 2024
fd9a1c2
fix(check-envs): func fix
kirill-ivanovvv Jul 1, 2024
9bf4440
feat(ui): add error message component
kirill-ivanovvv Jul 1, 2024
286544f
feat(theme): add color-const props to light and dark global object
kirill-ivanovvv Jul 1, 2024
d553d70
yarn
kirill-ivanovvv Jul 1, 2024
b2c02f1
fix: check env func fix
kirill-ivanovvv Jul 1, 2024
9abb4f4
refactor: root layout use layout
kirill-ivanovvv Jul 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6,077 changes: 5,161 additions & 916 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
packageExtensions:
'@graphql-codegen/plugin-helpers@*':
dependencies:
'@graphql-tools/apollo-engine-loader': '8.0.1'
glob-promise@*:
dependencies:
glob: '7.2.3'
Expand Down
13 changes: 13 additions & 0 deletions app/api/github-auth-cookie/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@app/github-auth-cookie-api",
"version": "0.0.1",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts"
},
"main": "src/index.ts",
"dependencies": {
"@globals/data": "workspace:*"
}
}
36 changes: 36 additions & 0 deletions app/api/github-auth-cookie/src/github-auth-cookie-handle.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// @ts-ignore:next-line
import { cookies } from 'next/headers'
// @ts-ignore:next-line
import { redirect } from 'next/navigation'

import { getGithubAuthToken } from '@globals/data'

import { COOKIE_EXPIRES_WEEK } from './github-auth-cookie-handle.constants.js'
import { RU_MESSAGES } from './github-auth-cookie-handle.messages.js'

export async function githubAuthCookieHandle(request: Request) {
const REQUEST_URL = new URL(request.url)
const REQUEST_ORIGIN = REQUEST_URL.origin
const { searchParams } = REQUEST_URL
const CODE = searchParams.get('code')

const REGISTRATION_URL = new URL('/registration', REQUEST_ORIGIN)

if (CODE) {
try {
const TOKEN = await getGithubAuthToken(CODE)

const { TOKEN_COOKIE_NAME } = process.env
cookies().set(TOKEN_COOKIE_NAME as string, TOKEN, {
expires: Date.now() + COOKIE_EXPIRES_WEEK,
})
} catch (e) {
// eslint-disable-next-line no-console
console.error(e)
REGISTRATION_URL.searchParams.set('errorMessage', RU_MESSAGES.tokenError)
return redirect(REGISTRATION_URL.href)
}
}

return redirect(REQUEST_ORIGIN)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const COOKIE_EXPIRES_WEEK = 1000 * 60 * 60 * 24 * 7
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const RU_MESSAGES = {
tokenError: 'Ошибка с получением TOKEN от GitHub',
}
1 change: 1 addition & 0 deletions app/api/github-auth-cookie/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './github-auth-cookie-handle.api.js'
10 changes: 10 additions & 0 deletions app/api/logout/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@app/logout-api",
"version": "0.0.1",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts"
},
"main": "src/index.ts"
}
1 change: 1 addition & 0 deletions app/api/logout/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './logout.api.js'
10 changes: 10 additions & 0 deletions app/api/logout/src/logout.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-ignore:next-line
import { cookies } from 'next/headers'
// @ts-ignore:next-line
import { redirect } from 'next/navigation'

export const logoutHandle = (request: Request) => {
cookies().delete('token')
const redirectUrl = new URL(request.url)
return redirect(redirectUrl.origin)
}
5 changes: 4 additions & 1 deletion app/entrypoints/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
"start": "node dist/src/index.cjs"
},
"dependencies": {
"graphql": "16.8.2",
"react-intl": "6.6.8"
},
"devDependencies": {
"@app/base-layout": "workspace:*",
"@app/github-auth-cookie-api": "workspace:*",
"@app/index-page": "workspace:*",
"@app/loading": "workspace:*",
"@app/logout-api": "workspace:*",
"@app/organizations-page": "workspace:*",
"@app/registration-page": "workspace:*",
"@app/root-layout": "workspace:*",
"@app/users-page": "workspace:*",
"@emotion/react": "11.11.4",
"@types/node": "20.12.12",
Expand All @@ -27,7 +31,6 @@
"next": "14.1.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-intl": "6.6.8",
"typescript": "5.2.2"
}
}
3 changes: 3 additions & 0 deletions app/entrypoints/renderer/src/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEXT_PUBLIC_GH_CLIENT_ID="Ov23li9kGqtVre5AFIeA"
NEXT_PUBLIC_GH_CLIENT_SECRET="234d7e0689b3f86506133b082896aa95c6fdf341"
TOKEN_COOKIE_NAME='token'
9 changes: 6 additions & 3 deletions app/entrypoints/renderer/src/app/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/* eslint-disable */

import React from 'react'
import { Suspense } from 'react'

import { BaseLayout } from '@app/base-layout'
import { Loading } from '@app/loading'

const Layout = ({ children }) => (
<BaseLayout>
<Suspense fallback={<Loading />}>{children}</Suspense>
</BaseLayout>
<Suspense fallback={<Loading />}>
{/* @ts-expect-error Async Server Component */}
<BaseLayout children={children} />
</Suspense>
)

export default Layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { githubAuthCookieHandle as GET } from '@app/github-auth-cookie-api'

export { GET }
20 changes: 5 additions & 15 deletions app/entrypoints/renderer/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
'use client'
import React from 'react'

import React from 'react'
import { IntlProvider } from 'react-intl'
import BaseRootLayout from '@app/root-layout'

import { ThemeProvider } from '@ui/theme'
import messages from '../../locales/ru.json'

import messages from '../../locales/ru.json'

const RootLayout = ({ children }) => (
<html>
<body>
<IntlProvider messages={messages} locale='ru' defaultLocale='ru'>
<ThemeProvider>{children}</ThemeProvider>
</IntlProvider>
</body>
</html>
)
// @ts-expect-error Async Server Component
const RootLayout = ({ children }) => <BaseRootLayout messages={messages}>{children}</BaseRootLayout>

export default RootLayout
3 changes: 3 additions & 0 deletions app/entrypoints/renderer/src/app/logout/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { logoutHandle as GET } from '@app/logout-api'

export { GET }
3 changes: 2 additions & 1 deletion app/entrypoints/renderer/src/app/registration/page.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default } from '@app/registration-page'
import { RegistrationClient } from '@app/registration-page'
export default RegistrationClient
17 changes: 17 additions & 0 deletions app/entrypoints/renderer/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @ts-ignore:next-line
import type { NextRequest } from 'next/server'

// @ts-ignore:next-line
import { NextResponse } from 'next/server'

export const middleware = (request: NextRequest) => {
const { TOKEN_COOKIE_NAME } = process.env
if (!request.cookies.has(TOKEN_COOKIE_NAME as string)) {
return NextResponse.redirect(new URL('/registration', request.url))
}
return NextResponse.next()
}

export const config = {
matcher: ['/organizations', '/users'],
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const AddMemberToOrganizationModal: FC<AddMemberToOrganizationModalProps>
<Modal open={open} width={theme.spaces.superPuperExtra} onBackdropClick={onBackdropClick}>
<Column flexDirection='column' gap={theme.spaces.large}>
<Text fontSize='medium.semiReduced' fontWeight='normal' padding={theme.spaces.micro}>
{formatMessage({ id: 'app-add-member-to-organization-modal.header' })}
{formatMessage({ id: 'add-member-to-organization-modal.header' })}
</Text>
<SelectInput
placeholder={formatMessage({ id: 'add-member-to-organization-modal_input.placeholder' })}
Expand All @@ -65,7 +65,7 @@ export const AddMemberToOrganizationModal: FC<AddMemberToOrganizationModalProps>
rowGap={theme.spaces.large}
>
<Text fontSize='normal.semiIncreased' width='100%'>
{formatMessage({ id: 'app-add-member-to-organization-modal.teams' })}
{formatMessage({ id: 'add-member-to-organization-modal.teams' })}
</Text>
<TeamSwitch teamName='Design' onChange={(e) => handlerSwitch(e, 'design')} />
<TeamSwitch teamName='Frontend' onChange={(e) => handlerSwitch(e, 'frontend')} />
Expand All @@ -80,7 +80,7 @@ export const AddMemberToOrganizationModal: FC<AddMemberToOrganizationModalProps>
size='middlingRoundedPadding'
>
<Text fontSize='normal.semiDefault' fontWeight='normal' color={theme.colors.white}>
{formatMessage({ id: 'app-add-member-to-organization-modal.button' })}
{formatMessage({ id: 'add-member-to-organization-modal.button' })}
</Text>
</Button>
</Row>
Expand Down
3 changes: 3 additions & 0 deletions app/fragments/app-base-layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
"dependencies": {
"@app/theme-selector": "workspace:*",
"@app/users-title": "workspace:*",
"@globals/data": "workspace:*",
"@ui/layout": "workspace:*",
"@ui/sidebar": "workspace:*"
},
"devDependencies": {
"@emotion/react": "11.11.4",
"@emotion/styled": "11.11.5",
"@octokit/graphql": "8.1.1",
"react": "18.3.1",
"react-dom": "18.3.1"
},
"peerDependencies": {
"@emotion/react": "*",
"@emotion/styled": "*",
"@octokit/graphql": "*",
"react": "*",
"react-dom": "*"
}
Expand Down
44 changes: 44 additions & 0 deletions app/fragments/app-base-layout/src/base-layout.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use client'

import type { GetViewerQuery } from '@globals/data'

import { useTheme } from '@emotion/react'

import React from 'react'
import { FC } from 'react'
import { PropsWithChildren } from 'react'

import { ThemeSelector } from '@app/theme-selector'
import { UsersTitle } from '@app/users-title'
import { Row } from '@ui/layout'
import { Column } from '@ui/layout'
import { Sidebar } from '@ui/sidebar'

import { BaseLayoutProps } from './base-layout.interfaces.js'

export const BaseLayoutClient: FC<PropsWithChildren<BaseLayoutProps>> = ({
children,
...baseLayoutData
}) => {
const theme: any = useTheme()
const { name, avatarUrl, email, url } = baseLayoutData as GetViewerQuery['viewer']

return (
<Row backgroundColor={theme.colors.baseLayout.background}>
<Sidebar name={name} email={email} avatarUrl={avatarUrl} url={url} />
<Column alignItems='center' flex={1}>
<ThemeSelector />
<Column
maxWidth={theme.spaces.extraSuperLarge}
margin={theme.spaces.horizontalAutoMargin}
gap={theme.spaces.large}
justifyContent='flex-start'
alignItems='flex-start'
>
<UsersTitle />
{children}
</Column>
</Column>
</Row>
)
}
44 changes: 6 additions & 38 deletions app/fragments/app-base-layout/src/base-layout.component.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,9 @@
'use client'
import React from 'react'

import { useTheme } from '@emotion/react'
import { BaseLayoutClient } from './base-layout.client.js'
import { BaseLayoutServer } from './base-layout.server.js'

import React from 'react'
import { FC } from 'react'
import { PropsWithChildren } from 'react'

import { ThemeSelector } from '@app/theme-selector'
import { UsersTitle } from '@app/users-title'
import { Row } from '@ui/layout'
import { Column } from '@ui/layout'
import { Sidebar } from '@ui/sidebar'

import { AVATAR } from './base-layout.constants.js'
import { EMAIL } from './base-layout.constants.js'
import { NAME } from './base-layout.constants.js'
import { BaseLayoutProps } from './base-layout.interfaces.js'

export const BaseLayout: FC<PropsWithChildren<BaseLayoutProps>> = ({ children }) => {
const theme: any = useTheme()
return (
<Row backgroundColor={theme.backgrounds.main}>
<Sidebar name={NAME} email={EMAIL} src={AVATAR} />
<Column alignItems='center' flex={1}>
<ThemeSelector />
<Column
maxWidth={theme.spaces.extraSuperLarge}
margin={theme.spaces.horizontalAutoMargin}
minHeight={theme.spaces.fullVh}
gap={theme.spaces.large}
justifyContent='flex-start'
alignItems='flex-start'
>
<UsersTitle />
{children}
</Column>
</Column>
</Row>
)
export const BaseLayout = async ({ children }) => {
const baseLayoutData = await BaseLayoutServer()
return <BaseLayoutClient {...baseLayoutData}>{children}</BaseLayoutClient>
}
3 changes: 0 additions & 3 deletions app/fragments/app-base-layout/src/base-layout.constants.ts

This file was deleted.

5 changes: 3 additions & 2 deletions app/fragments/app-base-layout/src/base-layout.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface BaseLayoutProps {
name?: string
name?: string | null | undefined
email?: string
avatar?: string
avatarUrl?: string
url?: string
}
26 changes: 26 additions & 0 deletions app/fragments/app-base-layout/src/base-layout.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { GetViewerQuery } from '@globals/data'

// @ts-ignore:next-line
import { cookies } from 'next/headers'
// @ts-ignore:next-line
import { redirect } from 'next/navigation'

import { GET_VIEWER } from '@globals/data'
import { octokitGraphqlClient } from '@globals/data'

export const BaseLayoutServer = async () => {
const { TOKEN_COOKIE_NAME } = process.env
const token = cookies().get(TOKEN_COOKIE_NAME as string).value
try {
const client = octokitGraphqlClient(token)
const response = (await client(GET_VIEWER)) as GetViewerQuery

const { viewer } = response
return viewer
} catch (e: any) {
if (e.status === 401) {
redirect('/registration')
}
throw e
}
}
18 changes: 18 additions & 0 deletions app/fragments/app-registration/src/github-auth.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @ts-ignore:next-line
import { useRouter } from 'next/navigation'

import { GH_AUTH_URL } from './registration.constants.js'
import { GH_AUTH_SCOPES } from './registration.constants.js'

export const githubAuthRedirectHook = (router: typeof useRouter) => {
const CURRENT_URL = new URL(window.location.href)

const GH_CLIENT_ID = process.env.NEXT_PUBLIC_GH_CLIENT_ID as string

GH_AUTH_URL.searchParams.set('client_id', GH_CLIENT_ID)
GH_AUTH_URL.searchParams.set('scope', GH_AUTH_SCOPES)

GH_AUTH_URL.searchParams.set('redirect_uri', `${CURRENT_URL.origin}/api/github-auth-cookie`)

router.replace(GH_AUTH_URL.href)
}
Loading