Skip to content

Commit

Permalink
Use quiver for validating session token
Browse files Browse the repository at this point in the history
  • Loading branch information
dumazy committed Dec 3, 2023
1 parent 792dff1 commit 6872e20
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tool/session_token.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:io';

import 'package:quiver/strings.dart';

const aocPath = '.dart_tool/aoc';
const sessionTokenPath = '$aocPath/.session_token';

Expand Down Expand Up @@ -30,7 +32,7 @@ void _writeSessionToken(String token) {
try {
File('$aocPath/$sessionTokenPath')
.create(recursive: true)
.then((file) => file.writeAsStringSync(token)),
.then((file) => file.writeAsStringSync(token));
} catch (e) {
print('Error writing session token: $e');
}
Expand All @@ -40,11 +42,11 @@ String _promptSessionToken() {
stdout.write(_kSessionTokenPromptMessage);
final token = stdin.readLineSync();
stdout.writeln();
if (token == null || token.isEmpty) {
if (isBlank(token)) {
print('Session token cannot be empty!');
return _promptSessionToken();
}
return token;
return token!;
}

const String _kSessionTokenPromptMessage = '''
Expand Down

0 comments on commit 6872e20

Please sign in to comment.