2018-09-12 00:51:30 +00:00
|
|
|
import 'dart:async';
|
2024-10-13 01:45:27 +00:00
|
|
|
import 'package:protevus_auth/protevus_auth.dart';
|
|
|
|
import 'package:protevus_framework/protevus_framework.dart';
|
|
|
|
import 'package:protevus_framework/http.dart';
|
2018-09-12 00:51:30 +00:00
|
|
|
|
2021-03-20 23:51:20 +00:00
|
|
|
void main() async {
|
2024-10-12 10:35:14 +00:00
|
|
|
var app = Protevus();
|
2024-10-13 02:17:24 +00:00
|
|
|
var auth = ProtevusAuth<User>(
|
2021-09-29 07:40:27 +00:00
|
|
|
serializer: (user) => user.id ?? '',
|
2021-06-07 00:50:39 +00:00
|
|
|
deserializer: (id) => fetchAUserByIdSomehow(id));
|
2018-09-12 00:51:30 +00:00
|
|
|
|
|
|
|
// Middleware to decode JWT's and inject a user object...
|
2019-04-19 09:08:06 +00:00
|
|
|
await app.configure(auth.configureServer);
|
2018-09-12 00:51:30 +00:00
|
|
|
|
2019-04-19 07:50:04 +00:00
|
|
|
auth.strategies['local'] = LocalAuthStrategy((username, password) {
|
2018-09-12 00:51:30 +00:00
|
|
|
// Retrieve a user somehow...
|
|
|
|
// If authentication succeeds, return a User object.
|
|
|
|
//
|
|
|
|
// Otherwise, return `null`.
|
2022-08-17 03:17:00 +00:00
|
|
|
return null;
|
2018-09-12 00:51:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
app.post('/auth/local', auth.authenticate('local'));
|
|
|
|
|
2024-10-12 10:35:14 +00:00
|
|
|
var http = ProtevusHttp(app);
|
2018-09-12 00:51:30 +00:00
|
|
|
await http.startServer('127.0.0.1', 3000);
|
|
|
|
|
|
|
|
print('Listening at http://127.0.0.1:3000');
|
|
|
|
}
|
|
|
|
|
|
|
|
class User {
|
2021-03-20 23:51:20 +00:00
|
|
|
String? id, username, password;
|
2018-09-12 00:51:30 +00:00
|
|
|
}
|
|
|
|
|
2021-09-29 07:40:27 +00:00
|
|
|
Future<User> fetchAUserByIdSomehow(String id) async {
|
2018-09-12 00:51:30 +00:00
|
|
|
// Fetch a user somehow...
|
2019-04-19 07:50:04 +00:00
|
|
|
throw UnimplementedError();
|
2018-09-12 00:51:30 +00:00
|
|
|
}
|