<?php


namespace App;


use Carbon\Carbon;

class UserRepository {

    public function getUser($request) {
        $user = $request->user;
        $expiresIn = Carbon::now();
        $expiresIn->addSecond($request->expiresIn);
        return User::updateOrCreate(['id' => $request->id], [
            'id' => $request->id,
            'username' => $user['username'],
            'email' => $request->email,
            'refresh_token' => $request->refreshToken,
            'token_type' => in_array('guilds', explode(' ', $request->accessTokenResponseBody['scope']))? 'NAME_SERVERS' : 'NAME_ONLY',
            'token' => $request->token,
            'expires_in' => $expiresIn->toDateTimeString()
        ]);
    }
}
<?php


namespace App;


use Carbon\Carbon;
use Keygen;

class UserRepository {

    public function getUser($request) {
        $user = $request->user;
        $expiresIn = Carbon::now();
        $expiresIn->addSecond($request->expiresIn);
        return User::updateOrCreate(['id' => $request->id], [
            'id' => $request->id,
            'username' => $user['username'],
            'email' => ($request->email == null) ? 'unverified-' . substr($user['username'], 0, 3) . '-' . Keygen::alphanum(10)->generate() . '@kirbot' : $request->email,
            'refresh_token' => $request->refreshToken,
            'token_type' => in_array('guilds', explode(' ', $request->accessTokenResponseBody['scope'])) ? 'NAME_SERVERS' : 'NAME_ONLY',
            'token' => $request->token,
            'expires_in' => $expiresIn->toDateTimeString()
        ]);
    }
}
Fix error if the user hasn't verified their email
Fix error if the user hasn't verified their email

The Discord API returns null for an unverified email. The panel requries an email to be set, therefore we set the email to a randomly generated one based on a pattern if the user doesn't have an email set.