@@ -151,8 +151,8 @@ import CustomFooter from '@/components/Footer.vue';
151
151
152
152
import { GTagLoginEvent } from ' @/gtag' ;
153
153
import * as fb from ' @/firebaseConfig' ;
154
-
155
- const { whitelistCollection, landingEmailsCollection } = fb ;
154
+ import store from ' @/store ' ;
155
+ import { checkNotNull } from ' @/utilities ' ;
156
156
157
157
type Data = {
158
158
loginForm: { email: string ; password: string };
@@ -185,88 +185,23 @@ export default Vue.extend({
185
185
fb .auth
186
186
.signInWithPopup (provider )
187
187
.then (user => {
188
- // Check whitelist emails to ensure user can log in
189
- if (user == null ) {
188
+ if (user == null || user .user == null ) {
190
189
return ;
191
190
}
192
- this .checkEmailAccess (user );
191
+ const simplifiedUser = {
192
+ displayName: checkNotNull (user .user .displayName ),
193
+ email: checkNotNull (user .user .email ),
194
+ };
195
+ store .commit (' setCurrentFirebaseUser' , simplifiedUser );
196
+ this .performingRequest = false ;
197
+ this .$router .push (' /' );
198
+ GTagLoginEvent (this .$gtag , ' Google' );
193
199
})
194
200
.catch (err => {
195
201
this .performingRequest = false ;
196
202
this .errorMsg = err .message ;
197
203
});
198
204
},
199
- checkEmailAccess({ user }: { user: firebase .User | null }) {
200
- if (user == null ) {
201
- return ;
202
- }
203
- const docRef = whitelistCollection .doc (user .email || ' ' );
204
- docRef
205
- .get ()
206
- .then (doc => {
207
- if (doc .exists ) {
208
- this .performingRequest = false ;
209
- this .$router .push (' /' );
210
- GTagLoginEvent (this .$gtag , ' Google' );
211
- } else {
212
- this .handleUserWithoutAccess ();
213
- }
214
- })
215
- .catch (() => this .handleUserWithoutAccess ());
216
- },
217
-
218
- handleUserWithoutAccess() {
219
- this .performingRequest = false ;
220
- fb .auth .signOut ();
221
- // eslint-disable-next-line no-alert
222
- alert (
223
- " Sorry, but you do not have access currently.\n Please check back April 5 for CoursePlan's public release."
224
- );
225
- },
226
-
227
- validateEmail(email : string ): boolean {
228
- return / ^ [^ \s @] + @[^ \s @] + \. [^ \s @] + $ / .test (email );
229
- },
230
- validateMajor(major : string ): boolean {
231
- return major .trim ().length > 0 ;
232
- },
233
- addUser() {
234
- if (this .validateEmail (this .waitlist .email ) && this .validateMajor (this .waitlist .major )) {
235
- // eslint-disable-next-line no-alert
236
- alert (" You have been added to the waitlist. We'll be in touch shortly!" );
237
-
238
- // Add timestamp to data in YYYY-MM-DD hh:mm:ss
239
- const dt = new Date ();
240
- this .waitlist .time = ` ${(dt .getMonth () + 1 )
241
- .toString ()
242
- .padStart (2 , ' 0' )}/${dt
243
- .getDate ()
244
- .toString ()
245
- .padStart (2 , ' 0' )}/${dt
246
- .getFullYear ()
247
- .toString ()
248
- .padStart (4 , ' 0' )} ${dt
249
- .getHours ()
250
- .toString ()
251
- .padStart (2 , ' 0' )}:${dt
252
- .getMinutes ()
253
- .toString ()
254
- .padStart (2 , ' 0' )}:${dt .getSeconds ().toString ().padStart (2 , ' 0' )} ` ;
255
-
256
- // Add landing page data to Firebase
257
- landingEmailsCollection .add (this .waitlist );
258
-
259
- // Clear fields
260
- this .waitlist .email = ' ' ;
261
- this .waitlist .major = ' ' ;
262
- } else if (! this .validateEmail (this .waitlist .email )) {
263
- // eslint-disable-next-line no-alert
264
- alert (' You have entered an invalid email address!' );
265
- } else {
266
- // eslint-disable-next-line no-alert
267
- alert (' You have not entered a major!' );
268
- }
269
- },
270
205
getYear(): number {
271
206
const today = new Date ();
272
207
return today .getFullYear ();
0 commit comments