Skip to content

Commit 7783df7

Browse files
committed
hide github token
For github.rest, use vscode settings (user setting, not .vscode/settings, so it won't tracked by source control). For dart source, use dotenv to save token in untracked .env, packages it as asset, and read the token at runtime.
1 parent fbc3b73 commit 7783df7

File tree

8 files changed

+208
-11
lines changed

8 files changed

+208
-11
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ app.*.map.json
4444
/android/app/debug
4545
/android/app/profile
4646
/android/app/release
47+
48+
*.env

.vscode/github.rest

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
@baseUrl = https://api.github.com
22

3-
@token = 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
3+
@token = {{githubToken}}
44

55
@acceptJson = application/vnd.github.v3+json
66

77
@acceptHTML = application/vnd.github.v3.html+json
88

99
GET {{baseUrl}}/user/starred
1010
?sort=stars
11-
?order=desc
12-
?page=1
11+
&order=desc
12+
&page=1
1313
Authorization: token {{token}}
1414
Accept: {{acceptJson}}
15+
#If-None-Match: W/"fc39e9c03134895d01a6b94e1cb27b1d805e339a1a8d41230c8ab02c239f112e"
1516

1617
###
1718

@@ -20,7 +21,7 @@ GET {{baseUrl}}/search/repositories
2021
&sort=stars
2122
&order=desc
2223
&page=1
23-
Authorization: token {{token}}
24+
# Authorization: token {{token}}
2425
Accept: {{acceptJson}}
2526

2627
###

lib/core/domain/fresh.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'package:freezed_annotation/freezed_annotation.dart';
2+
3+
part 'fresh.freezed.dart';
4+
5+
@freezed
6+
class Fresh<T> with _$Fresh<T> {
7+
const Fresh._();
8+
const factory Fresh({
9+
required T entity,
10+
required bool isFresh,
11+
}) = _Fresh<T>;
12+
}

lib/core/domain/fresh.freezed.dart

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
// coverage:ignore-file
2+
// GENERATED CODE - DO NOT MODIFY BY HAND
3+
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target
4+
5+
part of 'fresh.dart';
6+
7+
// **************************************************************************
8+
// FreezedGenerator
9+
// **************************************************************************
10+
11+
T _$identity<T>(T value) => value;
12+
13+
final _privateConstructorUsedError = UnsupportedError(
14+
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
15+
16+
/// @nodoc
17+
class _$FreshTearOff {
18+
const _$FreshTearOff();
19+
20+
_Fresh<T> call<T>({required T entity, required bool isFresh}) {
21+
return _Fresh<T>(
22+
entity: entity,
23+
isFresh: isFresh,
24+
);
25+
}
26+
}
27+
28+
/// @nodoc
29+
const $Fresh = _$FreshTearOff();
30+
31+
/// @nodoc
32+
mixin _$Fresh<T> {
33+
T get entity => throw _privateConstructorUsedError;
34+
bool get isFresh => throw _privateConstructorUsedError;
35+
36+
@JsonKey(ignore: true)
37+
$FreshCopyWith<T, Fresh<T>> get copyWith =>
38+
throw _privateConstructorUsedError;
39+
}
40+
41+
/// @nodoc
42+
abstract class $FreshCopyWith<T, $Res> {
43+
factory $FreshCopyWith(Fresh<T> value, $Res Function(Fresh<T>) then) =
44+
_$FreshCopyWithImpl<T, $Res>;
45+
$Res call({T entity, bool isFresh});
46+
}
47+
48+
/// @nodoc
49+
class _$FreshCopyWithImpl<T, $Res> implements $FreshCopyWith<T, $Res> {
50+
_$FreshCopyWithImpl(this._value, this._then);
51+
52+
final Fresh<T> _value;
53+
// ignore: unused_field
54+
final $Res Function(Fresh<T>) _then;
55+
56+
@override
57+
$Res call({
58+
Object? entity = freezed,
59+
Object? isFresh = freezed,
60+
}) {
61+
return _then(_value.copyWith(
62+
entity: entity == freezed
63+
? _value.entity
64+
: entity // ignore: cast_nullable_to_non_nullable
65+
as T,
66+
isFresh: isFresh == freezed
67+
? _value.isFresh
68+
: isFresh // ignore: cast_nullable_to_non_nullable
69+
as bool,
70+
));
71+
}
72+
}
73+
74+
/// @nodoc
75+
abstract class _$FreshCopyWith<T, $Res> implements $FreshCopyWith<T, $Res> {
76+
factory _$FreshCopyWith(_Fresh<T> value, $Res Function(_Fresh<T>) then) =
77+
__$FreshCopyWithImpl<T, $Res>;
78+
@override
79+
$Res call({T entity, bool isFresh});
80+
}
81+
82+
/// @nodoc
83+
class __$FreshCopyWithImpl<T, $Res> extends _$FreshCopyWithImpl<T, $Res>
84+
implements _$FreshCopyWith<T, $Res> {
85+
__$FreshCopyWithImpl(_Fresh<T> _value, $Res Function(_Fresh<T>) _then)
86+
: super(_value, (v) => _then(v as _Fresh<T>));
87+
88+
@override
89+
_Fresh<T> get _value => super._value as _Fresh<T>;
90+
91+
@override
92+
$Res call({
93+
Object? entity = freezed,
94+
Object? isFresh = freezed,
95+
}) {
96+
return _then(_Fresh<T>(
97+
entity: entity == freezed
98+
? _value.entity
99+
: entity // ignore: cast_nullable_to_non_nullable
100+
as T,
101+
isFresh: isFresh == freezed
102+
? _value.isFresh
103+
: isFresh // ignore: cast_nullable_to_non_nullable
104+
as bool,
105+
));
106+
}
107+
}
108+
109+
/// @nodoc
110+
111+
class _$_Fresh<T> extends _Fresh<T> {
112+
const _$_Fresh({required this.entity, required this.isFresh}) : super._();
113+
114+
@override
115+
final T entity;
116+
@override
117+
final bool isFresh;
118+
119+
@override
120+
String toString() {
121+
return 'Fresh<$T>(entity: $entity, isFresh: $isFresh)';
122+
}
123+
124+
@override
125+
bool operator ==(dynamic other) {
126+
return identical(this, other) ||
127+
(other is _Fresh<T> &&
128+
(identical(other.entity, entity) ||
129+
const DeepCollectionEquality().equals(other.entity, entity)) &&
130+
(identical(other.isFresh, isFresh) ||
131+
const DeepCollectionEquality().equals(other.isFresh, isFresh)));
132+
}
133+
134+
@override
135+
int get hashCode =>
136+
runtimeType.hashCode ^
137+
const DeepCollectionEquality().hash(entity) ^
138+
const DeepCollectionEquality().hash(isFresh);
139+
140+
@JsonKey(ignore: true)
141+
@override
142+
_$FreshCopyWith<T, _Fresh<T>> get copyWith =>
143+
__$FreshCopyWithImpl<T, _Fresh<T>>(this, _$identity);
144+
}
145+
146+
abstract class _Fresh<T> extends Fresh<T> {
147+
const factory _Fresh({required T entity, required bool isFresh}) =
148+
_$_Fresh<T>;
149+
const _Fresh._() : super._();
150+
151+
@override
152+
T get entity => throw _privateConstructorUsedError;
153+
@override
154+
bool get isFresh => throw _privateConstructorUsedError;
155+
@override
156+
@JsonKey(ignore: true)
157+
_$FreshCopyWith<T, _Fresh<T>> get copyWith =>
158+
throw _privateConstructorUsedError;
159+
}

lib/github/repos/starred/infra/starred_repos_remote_service.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:io';
22

33
import 'package:dio/dio.dart';
4+
import 'package:flutter_dotenv/flutter_dotenv.dart';
45
import 'package:repo_viewer/core/infra/dio_extensions.dart';
56
import 'package:repo_viewer/core/infra/network_exceptions.dart';
67
import 'package:repo_viewer/core/infra/remote_response.dart';
@@ -20,7 +21,7 @@ class StarredReposRemoteService {
2021

2122
Future<RemoteResponse<List<GithubRepoDTO>>> getStarredReposPage(
2223
int page) async {
23-
const token = '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';
24+
final token = dotenv.env['GITHUB_TOKEN'];
2425
const accept = 'application/vnd.github.v3+json';
2526
final reqURL = Uri.https(
2627
'api.github.com',

lib/main.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_dotenv/flutter_dotenv.dart';
23
import 'package:hooks_riverpod/hooks_riverpod.dart';
34
import 'package:repo_viewer/core/presentation/app_widget.dart';
45

5-
void main() => runApp(
6-
ProviderScope(
7-
child: AppWidget(),
8-
),
9-
);
6+
void main() async {
7+
await dotenv.load(fileName: ".env");
8+
runApp(
9+
ProviderScope(
10+
child: AppWidget(),
11+
),
12+
);
13+
}

pubspec.lock

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ packages:
237237
description: flutter
238238
source: sdk
239239
version: "0.0.0"
240+
flutter_dotenv:
241+
dependency: "direct main"
242+
description:
243+
name: flutter_dotenv
244+
url: "https://pub.dartlang.org"
245+
source: hosted
246+
version: "5.0.2"
240247
flutter_hooks:
241248
dependency: "direct main"
242249
description:
@@ -400,6 +407,13 @@ packages:
400407
url: "https://pub.dartlang.org"
401408
source: hosted
402409
version: "0.12.11"
410+
material_color_utilities:
411+
dependency: transitive
412+
description:
413+
name: material_color_utilities
414+
url: "https://pub.dartlang.org"
415+
source: hosted
416+
version: "0.1.3"
403417
material_design_icons_flutter:
404418
dependency: "direct main"
405419
description:
@@ -644,7 +658,7 @@ packages:
644658
name: test_api
645659
url: "https://pub.dartlang.org"
646660
source: hosted
647-
version: "0.4.3"
661+
version: "0.4.8"
648662
timing:
649663
dependency: transitive
650664
description:

pubspec.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies:
1515
flash: ^2.0.3
1616
flutter:
1717
sdk: flutter
18+
flutter_dotenv: ^5.0.2
1819
flutter_hooks: ^0.16.0
1920
flutter_secure_storage: ^4.2.1
2021
freezed_annotation: ^0.14.2
@@ -55,3 +56,6 @@ dependency_overrides:
5556

5657
flutter:
5758
uses-material-design: true
59+
60+
assets:
61+
- .env

0 commit comments

Comments
 (0)