Skip to content

Commit

Permalink
fix(authentication): add clientId in magic link token data
Browse files Browse the repository at this point in the history
  • Loading branch information
kkopanidis committed Oct 3, 2022
1 parent 7c9df4b commit 7a9f776
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions modules/authentication/src/handlers/magicLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@ export class MagicLinkHandlers implements IAuthenticationStrategy {

async sendMagicLink(call: ParsedRouterRequest): Promise<UnparsedRouterResponse> {
const { email } = call.request.params;
const { clientId } = call.request.context;
const user: User | null = await User.getInstance().findOne({ email: email });
if (isNil(user)) throw new GrpcError(status.NOT_FOUND, 'User not found');

const token: Token = await Token.getInstance().create({
type: TokenType.MAGIC_LINK,
user: user._id,
data: {
clientId,
},
token: uuid(),
});

Expand All @@ -104,9 +108,6 @@ export class MagicLinkHandlers implements IAuthenticationStrategy {

async verifyLogin(call: ParsedRouterRequest): Promise<UnparsedRouterResponse> {
const { verificationToken } = call.request.params.verificationToken;
const context = call.request.context;

const clientId = context.clientId;
const config = ConfigController.getInstance().config;
const redirectUri = config.magic_link.redirect_uri;
const token: Token | null = await Token.getInstance().findOne({
Expand All @@ -130,7 +131,7 @@ export class MagicLinkHandlers implements IAuthenticationStrategy {
return TokenProvider.getInstance()!.provideUserTokens(
{
user,
clientId,
clientId: token.data.clientId,
config,
},
redirectUri,
Expand Down

0 comments on commit 7a9f776

Please sign in to comment.