schema
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions
Deploy Telegram Bot / Deploy Telegram Bot (push) Waiting to run
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions
Deploy Telegram Bot / Deploy Telegram Bot (push) Waiting to run
This commit is contained in:
parent
9ca6d9ea4f
commit
1ec209108a
2 changed files with 7 additions and 28 deletions
|
|
@ -2,13 +2,12 @@ import 'dart:convert';
|
|||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:mnemo_cards_backend/api/authorize/helpers.dart';
|
||||
import 'package:mnemo_cards_backend/api/v2/jwt_service.dart';
|
||||
import 'package:mnemo_cards_backend/auth/telegram_auth_code_service.dart';
|
||||
import 'package:mnemo_cards_backend/user/admin_ids_service.dart';
|
||||
import 'package:mnemo_cards_backend/user/user_manager.dart';
|
||||
import 'package:mnemo_cards_common_backend/mnemo_cards_common_backend.dart';
|
||||
import 'package:shelf/shelf.dart';
|
||||
import 'package:shelf_router/shelf_router.dart';
|
||||
import 'package:jaguar_jwt/jaguar_jwt.dart';
|
||||
|
||||
part 'admin_auth_api_v2.g.dart';
|
||||
|
||||
|
|
@ -17,10 +16,12 @@ part 'admin_auth_api_v2.g.dart';
|
|||
class AdminAuthApiV2 {
|
||||
final TelegramAuthCodeService _telegramAuthCodeService;
|
||||
final UserManager _userManager;
|
||||
final JwtService _jwtService;
|
||||
|
||||
AdminAuthApiV2(
|
||||
this._telegramAuthCodeService,
|
||||
this._userManager,
|
||||
this._jwtService,
|
||||
);
|
||||
|
||||
Response _json(
|
||||
|
|
@ -157,12 +158,12 @@ class AdminAuthApiV2 {
|
|||
);
|
||||
}
|
||||
|
||||
// Generate JWT token
|
||||
final token = _generateJwtToken(user);
|
||||
// Generate JWT token using JwtService (same as regular auth)
|
||||
final tokens = await _jwtService.generateTokens(user);
|
||||
|
||||
return _json({
|
||||
'success': true,
|
||||
'token': token,
|
||||
'token': tokens.accessToken,
|
||||
'user': {
|
||||
'id': user.id,
|
||||
'name': user.name,
|
||||
|
|
@ -270,28 +271,5 @@ class AdminAuthApiV2 {
|
|||
return AdminIdsService.getAdminIds();
|
||||
}
|
||||
|
||||
/// Generate JWT token for admin user
|
||||
String _generateJwtToken(UserModel user) {
|
||||
final claimSet = JwtClaim(
|
||||
issuer: 'mnemo-cards-admin',
|
||||
subject: user.id.toString(),
|
||||
audience: const ['admin-panel'],
|
||||
issuedAt: DateTime.now(),
|
||||
expiry: DateTime.now().add(const Duration(hours: 24)), // 24 hours
|
||||
payload: {
|
||||
'userId': user.id,
|
||||
'admin': true,
|
||||
// Note: UserModel doesn't have telegramUserId field
|
||||
// 'telegramUserId': user.telegramUserId,
|
||||
},
|
||||
);
|
||||
|
||||
// Use a secure secret key (should be from environment/config)
|
||||
const secret = 'your-admin-jwt-secret-key-change-this-in-production';
|
||||
|
||||
final token = issueJwtHS256(claimSet, secret);
|
||||
return token;
|
||||
}
|
||||
|
||||
Router get router => _$AdminAuthApiV2Router(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ class IsarConnector {
|
|||
UserTaskProgressModelSchema,
|
||||
UserTaskResultModelSchema,
|
||||
ShareRequestModelSchema,
|
||||
StudySessionModelSchema,
|
||||
],
|
||||
directory: dir,
|
||||
name: 'db',
|
||||
|
|
|
|||
Loading…
Reference in a new issue