@@ -19,6 +19,8 @@ import {
1919 RefreshResponse ,
2020 SignUpBodyRequest ,
2121 SignUpResponse ,
22+ TelegramLoginBodyRequest ,
23+ TelegramLoginResponse ,
2224} from '../model/types/auth' ;
2325
2426export const authApi = baseApi . injectEndpoints ( {
@@ -48,6 +50,28 @@ export const authApi = baseApi.injectEndpoints({
4850 }
4951 } ,
5052 } ) ,
53+ telegram : build . mutation < TelegramLoginResponse , TelegramLoginBodyRequest > ( {
54+ query : ( body ) => ( {
55+ url : authApiUrls . telegram ,
56+ method : 'POST' ,
57+ body,
58+ } ) ,
59+ async onQueryStarted ( _ , { queryFulfilled, extra } ) {
60+ try {
61+ const result = await queryFulfilled ;
62+ setToLS ( LS_ACCESS_TOKEN_KEY , result . data . access_token ) ;
63+ const typedExtra = extra as ExtraArgument ;
64+ typedExtra . navigate ( ROUTES . platformRoute ) ;
65+ } catch ( error ) {
66+ if ( error && typeof error === 'object' && 'error' in error ) {
67+ const errObj = error as { error : { data : { message : string } } } ;
68+ toast . error ( i18n . t ( 'toast.' + errObj . error . data . message ) ) ;
69+ }
70+ // eslint-disable-next-line no-console
71+ console . error ( error ) ;
72+ }
73+ } ,
74+ } ) ,
5175 register : build . mutation < SignUpResponse , SignUpBodyRequest > ( {
5276 query : ( body ) => ( {
5377 url : authApiUrls . register ,
@@ -126,6 +150,7 @@ export const authApi = baseApi.injectEndpoints({
126150
127151export const {
128152 useLoginMutation,
153+ useTelegramMutation,
129154 useRegisterMutation,
130155 useProfileQuery,
131156 useLazyLogoutQuery,
0 commit comments