Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: top level domain set in the cookie #166

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: use the tldjs for get the top level domain
  • Loading branch information
zeelrupapara committed Jun 2, 2024
commit a4db64e69d9a6fa4fee6ab5ae17ddc47e763a59c
3 changes: 2 additions & 1 deletion packages/medusa-plugin-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"passport-firebase-jwt": "^1.2.1",
"passport-google-oauth2": "^0.2.0",
"passport-linkedin-oauth2": "^2.0.0",
"passport-oauth2": "^1.7.0"
"passport-oauth2": "^1.7.0",
"tldjs": "^2.3.1"
},
"jest": {
"preset": "ts-jest",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cors from 'cors';
import { authCallbackMiddleware, authenticateSessionFactory, signToken } from '../../auth-callback-middleware';
import { ConfigModule } from '@medusajs/medusa/dist/types/global';
import { CookieOptions } from 'express-serve-static-core';
import { getDomain } from 'tldjs'

type PassportAuthenticateMiddlewareOptions = {
[key: string]: unknown;
Expand All @@ -15,16 +16,6 @@ type PassportCallbackAuthenticateMiddlewareOptions = {
failureRedirect: string;
};

export const extractDomain = (url) => {
const domain = url.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/im)[1];
const mainDomain = domain.split('.');
if (mainDomain.length > 2) {
// Return the domain and top-level domain (TLD)
return mainDomain.slice(-2).join('.');
}
return domain;
};

/**
* Build and return a router including the different route and configuration for a passport strategy
* @param domain
Expand Down Expand Up @@ -138,7 +129,7 @@ function successActionHandlerFactory(
const returnAccessToken = req.query.returnAccessToken == 'true';
const redirectUrl = (req.query.redirectTo ? req.query.redirectTo : defaultRedirect) as string;
const isProdOrStaging = process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging';
const originHost = isProdOrStaging ? req.get('referer') && extractDomain(req.get('referer')) : undefined;
const originHost = isProdOrStaging ? req.get('referer') && getDomain(req.get('referer')) : undefined;

if (returnAccessToken) {
return (req: Request, res: Response) => {
Expand Down
Loading