Add JWT auth for protected routes, add /reg endpoint, remove /user endpoints
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:shelf/shelf.dart';
|
||||
import 'package:shelf_router/shelf_router.dart';
|
||||
import '../database/database_provider.dart';
|
||||
import '../middleware/auth_middleware.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
class GeoRoutes {
|
||||
@@ -10,9 +11,9 @@ class GeoRoutes {
|
||||
|
||||
Router get routes {
|
||||
final router = Router();
|
||||
router.post('/geo', _createPosition);
|
||||
router.put('/geo', _updatePosition);
|
||||
router.post('/share', _createShare);
|
||||
router.post('/geo', AuthMiddleware(_createPosition).call);
|
||||
router.put('/geo', AuthMiddleware(_updatePosition).call);
|
||||
router.post('/share', AuthMiddleware(_createShare).call);
|
||||
return router;
|
||||
}
|
||||
|
||||
@@ -20,13 +21,10 @@ class GeoRoutes {
|
||||
final body = await request.readAsString();
|
||||
final data = jsonDecode(body);
|
||||
|
||||
final userId = data['user_id'];
|
||||
final x = data['x'];
|
||||
final y = data['y'];
|
||||
final lifetimeSeconds = data['lifetime'];
|
||||
final lifetime = Duration(seconds: lifetimeSeconds);
|
||||
|
||||
final position = await database.createPosition(userId, x, y, lifetime);
|
||||
final position = await database.createPosition(x, y);
|
||||
return Response(201, body: position.toJson());
|
||||
}
|
||||
|
||||
@@ -34,22 +32,15 @@ class GeoRoutes {
|
||||
final body = await request.readAsString();
|
||||
final data = jsonDecode(body);
|
||||
|
||||
final userId = data['user_id'];
|
||||
final x = data['x'];
|
||||
final y = data['y'];
|
||||
final lifetimeSeconds = data['lifetime'];
|
||||
final lifetime = Duration(seconds: lifetimeSeconds);
|
||||
|
||||
final position = await database.updatePosition(userId, x, y, lifetime);
|
||||
final position = await database.updatePosition(x, y);
|
||||
return Response(200, body: position.toJson());
|
||||
}
|
||||
|
||||
Future<Response> _createShare(Request request) async {
|
||||
final body = await request.readAsString();
|
||||
final data = jsonDecode(body);
|
||||
|
||||
final userId = data['user_id'];
|
||||
final shareId = database.createShareId(userId);
|
||||
final shareId = database.createShareId();
|
||||
|
||||
return Response(200, body: jsonEncode({'share_id': shareId}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user