Skip to content

Commit 077b3be

Browse files
authored
Merge pull request #53 from teacoder-team/dev
Dev
2 parents 487ed65 + 8ce928a commit 077b3be

49 files changed

Lines changed: 578 additions & 372 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/api/hooks/useLogout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { logout } from '../requests'
44

55
export const useLogout = (
66
options?: Omit<
7-
UseMutationOptions<void, unknown, void>,
7+
UseMutationOptions<unknown, unknown, void>,
88
'mutationKey' | 'mutationFn'
99
>
1010
) =>

src/api/hooks/useVerifyMfa.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ import {
88
verifyMfa
99
} from '../requests'
1010

11-
type MfaVerifyRequest =
12-
| VerifyTotpRequest
13-
| VerifyPasskeyRequest
14-
| VerifyRecoveryRequest
11+
type AnalyticsMeta = {
12+
method?: string
13+
}
14+
15+
export type MfaVerifyRequest =
16+
| (VerifyTotpRequest & AnalyticsMeta)
17+
| (VerifyPasskeyRequest & AnalyticsMeta)
18+
| (VerifyRecoveryRequest & AnalyticsMeta)
1519

1620
export const useVerifyMfa = (
1721
options?: Omit<

src/api/instance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios from 'axios'
22

33
import { APP_CONFIG } from '../constants/app'
4-
import { getSessionToken } from '../lib/cookies/session'
4+
import { cookies } from '../lib/cookie'
55

66
export const api = axios.create({
77
baseURL: APP_CONFIG.apiUrl
@@ -10,6 +10,6 @@ export const api = axios.create({
1010
export const instance = axios.create({
1111
baseURL: APP_CONFIG.apiUrl,
1212
headers: {
13-
'X-Session-Token': getSessionToken() ?? ''
13+
'X-Session-Token': cookies.get('token') ?? ''
1414
}
1515
})

src/api/requests/account.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,13 @@ import type {
99
} from '../generated'
1010
import { api, instance } from '../instance'
1111

12-
import { setSessionToken } from '@/src/lib/cookies/session'
13-
1412
export const getMe = async () =>
15-
await instance
16-
.get<AccountResponse>('/auth/account')
17-
.then(response => response.data)
18-
19-
export const createAccount = async (data: CreateUserRequest) => {
20-
const response = await api.post<CreateUserResponse>(
21-
'/auth/account/create',
22-
data
23-
)
24-
25-
if (response.data.token) {
26-
setSessionToken(response.data.token)
27-
28-
instance.defaults.headers['X-Session-Token'] = response.data.token
29-
}
13+
await instance.get<AccountResponse>('/auth/account').then(res => res.data)
3014

31-
return response.data
32-
}
15+
export const createAccount = async (data: CreateUserRequest) =>
16+
await api
17+
.post<CreateUserResponse>('/auth/account/create', data)
18+
.then(res => res.data)
3319

3420
export const sendEmailVerification = () => instance.post('/auth/account/verify')
3521

src/api/requests/session.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import type {
66
} from '../generated'
77
import { api, instance } from '../instance'
88

9-
import { removeSessionToken } from '@/src/lib/cookies/session'
10-
119
export const login = async (data: LoginRequest) =>
1210
await api
1311
.post<
@@ -16,9 +14,7 @@ export const login = async (data: LoginRequest) =>
1614
.then(response => response.data)
1715

1816
export const logout = async () =>
19-
await instance
20-
.post<boolean>('/auth/session/logout')
21-
.then(() => removeSessionToken())
17+
await instance.post<boolean>('/auth/session/logout')
2218

2319
export const getSessions = async () =>
2420
await instance

src/app/(public)/courses/[slug]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { notFound } from 'next/navigation'
33

44
import { getCourse, getCourseLessons, getCourses } from '@/src/api/requests'
55
import { CourseDetails } from '@/src/components/course/course-details'
6-
import { CourseProvider } from '@/src/components/providers/course-provider'
76
import { getMediaSource } from '@/src/lib/utils'
7+
import { CourseProvider } from '@/src/providers/course-provider'
88

99
export async function generateStaticParams() {
1010
const courses = await getCourses()

src/app/account/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ReactNode } from 'react'
22

33
import { Header } from '@/src/components/layout/header'
44
import { UserNavigation } from '@/src/components/layout/user-navigation'
5-
import { AccountProvider } from '@/src/components/providers/account-provider'
5+
import { AccountProvider } from '@/src/providers'
66

77
export default function AccountLayout({ children }: { children: ReactNode }) {
88
return (

src/app/auth/callback/page.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { useEffect } from 'react'
55

66
import { instance } from '@/src/api/instance'
77
import { EllipsisLoader } from '@/src/components/shared/ellipsis-loader'
8-
import { setSessionToken } from '@/src/lib/cookies/session'
8+
import { ROUTES } from '@/src/constants'
9+
import { cookies } from '@/src/lib/cookie'
910

1011
export default function AuthCallbackPage() {
1112
const router = useRouter()
@@ -15,9 +16,11 @@ export default function AuthCallbackPage() {
1516
const token = new URLSearchParams(hash.slice(1)).get('token')
1617

1718
if (token) {
18-
setSessionToken(token)
19+
cookies.set('token', token, { expires: 30 })
20+
1921
instance.defaults.headers['X-Session-Token'] = token
20-
router.push('/account/settings')
22+
23+
router.push(ROUTES.ACCOUNT.ROOT)
2124
}
2225
}, [router])
2326

src/app/auth/telegram-oauth-finish/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use client'
22

33
import { useRouter } from 'next/navigation'
4-
import { useEffect, useState } from 'react'
4+
import { useEffect } from 'react'
55

66
import { TelegramAuthRequest } from '@/src/api/generated'
77
import { useTelegramAuth } from '@/src/api/hooks'
88
import { instance } from '@/src/api/instance'
99
import { EllipsisLoader } from '@/src/components/shared/ellipsis-loader'
1010
import { ROUTES } from '@/src/constants'
1111
import { useFingerprint } from '@/src/hooks'
12-
import { setSessionToken } from '@/src/lib/cookies/session'
12+
import { cookies } from '@/src/lib/cookie'
1313

1414
function base64DecodeUnicode(str: string) {
1515
try {
@@ -32,7 +32,7 @@ export default function TelegramAuthFinishPage() {
3232

3333
const { mutate } = useTelegramAuth({
3434
onSuccess(data) {
35-
setSessionToken(data.token)
35+
cookies.set('token', data.token, { expires: 30 })
3636

3737
instance.defaults.headers['X-Session-Token'] = data.token
3838

src/app/layout.tsx

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { GoogleAnalytics } from '@next/third-parties/google'
21
import { GeistSans } from 'geist/font/sans'
32
import type { Metadata } from 'next'
43
import type { ReactNode } from 'react'
54

6-
import { YandexMetrika } from '../components/analitycs/yandex-metrika'
7-
import { BanChecker } from '../components/providers/ban-checker'
8-
import { FingerprintProvider } from '../components/providers/fingerprint-provider'
9-
import { PosthogProvider } from '../components/providers/posthog-provider'
10-
import { TanstackQueryProvider } from '../components/providers/tanstack-query-provider'
11-
import { ThemeProvider } from '../components/providers/theme-provider'
125
import { Toaster } from '../components/shared/sonner'
136
import { APP_CONFIG, SEO } from '../constants'
7+
import { YandexMetrikaScript } from '../lib/analytics/script-providers'
8+
import {
9+
AnalyticsProvider,
10+
BanChecker,
11+
FingerprintProvider,
12+
TanstackQueryProvider,
13+
ThemeProvider
14+
} from '../providers'
1415

1516
import '@/src/styles/globals.css'
1617

@@ -73,7 +74,7 @@ export default function RootLayout({ children }: { children: ReactNode }) {
7374
<html className={GeistSans.variable} lang='ru' suppressHydrationWarning>
7475
<body className='flex h-full w-full flex-col font-sans'>
7576
<TanstackQueryProvider>
76-
<PosthogProvider>
77+
<AnalyticsProvider>
7778
<FingerprintProvider>
7879
<ThemeProvider
7980
attribute='class'
@@ -99,25 +100,12 @@ export default function RootLayout({ children }: { children: ReactNode }) {
99100
{process.env['NEXT_PUBLIC_NODE_ENV'] ===
100101
'production' && (
101102
<>
102-
<YandexMetrika
103-
id={
104-
process.env[
105-
'NEXT_PUBLIC_YANDEX_METRIKA_ID'
106-
] ?? ''
107-
}
108-
/>
109-
<GoogleAnalytics
110-
gaId={
111-
process.env[
112-
'NEXT_PUBLIC_GOOGLE_ANALYTICS_ID'
113-
] ?? ''
114-
}
115-
/>
103+
<YandexMetrikaScript />
116104
</>
117105
)}
118106
</ThemeProvider>
119107
</FingerprintProvider>
120-
</PosthogProvider>
108+
</AnalyticsProvider>
121109
</TanstackQueryProvider>
122110
</body>
123111
</html>

0 commit comments

Comments
 (0)