diff --git a/apps/web/.gitignore b/apps/web/.gitignore
index e1753567..59d3e5b9 100644
--- a/apps/web/.gitignore
+++ b/apps/web/.gitignore
@@ -43,3 +43,5 @@ next.config.original.js
# Sentry Config File
.sentryclirc
+
+certificates
\ No newline at end of file
diff --git a/apps/web/app/auth/cookies.ts b/apps/web/app/auth/cookies.ts
new file mode 100644
index 00000000..7c461f05
--- /dev/null
+++ b/apps/web/app/auth/cookies.ts
@@ -0,0 +1,70 @@
+import { LEARNHOUSE_TOP_DOMAIN } from '@services/config/config'
+
+const cookiePrefix = '__LRN-'
+const cookieDomain =
+ LEARNHOUSE_TOP_DOMAIN == `.${LEARNHOUSE_TOP_DOMAIN}`
+const cookieSecure = LEARNHOUSE_TOP_DOMAIN == 'localhost' ? true : true
+const cookieSameSite = LEARNHOUSE_TOP_DOMAIN == 'localhost' ? 'lax' : 'None'
+
+export const cookiesOptions = {
+ sessionToken: {
+ name: `__Secure-next-auth.session-token`,
+ options: {
+ domain: cookieDomain,
+ httpOnly: true,
+ sameSite: cookieSameSite,
+ path: '/',
+ secure: cookieSecure,
+ },
+ },
+ callbackUrl: {
+ name: `__Secure-next-auth.callback-url`,
+ options: {
+ domain: cookieDomain,
+ httpOnly: true,
+ sameSite: cookieSameSite,
+ path: '/',
+ secure: cookieSecure,
+ },
+ },
+ csrfToken: {
+ name: `__Host-next-auth.csrf-token`,
+ options: {
+ domain: cookieDomain,
+ httpOnly: true,
+ sameSite: cookieSameSite,
+ path: '/',
+ secure: cookieSecure,
+ },
+ },
+ pkceCodeVerifier: {
+ name: `${cookiePrefix}next-auth.pkce.code_verifier`,
+ options: {
+ domain: cookieDomain,
+ httpOnly: true,
+ sameSite: cookieSameSite,
+ path: '/',
+ secure: cookieSecure,
+ },
+ },
+ state: {
+ name: `${cookiePrefix}next-auth.state`,
+ options: {
+ domain: cookieDomain,
+ httpOnly: true,
+ sameSite: cookieSameSite,
+ path: '/',
+ secure: cookieSecure,
+ },
+ },
+ nonce: {
+ name: `${cookiePrefix}next-auth.nonce`,
+ options: {
+ domain: cookieDomain,
+ httpOnly: true,
+ sameSite: cookieSameSite,
+ path: '/',
+ secure: cookieSecure,
+ },
+ },
+}
diff --git a/apps/web/app/auth/options.ts b/apps/web/app/auth/options.ts
index 6559887d..9a7e751d 100644
--- a/apps/web/app/auth/options.ts
+++ b/apps/web/app/auth/options.ts
@@ -4,11 +4,16 @@ import {
loginAndGetToken,
loginWithOAuthToken,
} from '@services/auth/auth'
+import { LEARNHOUSE_TOP_DOMAIN, getUriWithOrg } from '@services/config/config'
import { getResponseMetadata } from '@services/utils/ts/requests'
import CredentialsProvider from 'next-auth/providers/credentials'
import GoogleProvider from 'next-auth/providers/google'
+import { cookiesOptions } from './cookies'
+
+const isDevEnv = LEARNHOUSE_TOP_DOMAIN == 'localhost' ? true : false
export const nextAuthOptions = {
+ debug: true,
providers: [
CredentialsProvider({
// The name to display on the sign in form (e.g. 'Sign in with...')
@@ -41,6 +46,24 @@ export const nextAuthOptions = {
clientSecret: process.env.LEARNHOUSE_GOOGLE_CLIENT_SECRET || '',
}),
],
+ pages: {
+ signIn: getUriWithOrg('auth', '/'),
+ verifyRequest: getUriWithOrg('auth', '/'),
+ error: getUriWithOrg('auth', '/'), // Error code passed in query string as ?error=
+ },
+ cookies: {
+ sessionToken: {
+ name: `${!isDevEnv ? '__Secure-' : ''}next-auth.session-token`,
+ options: {
+ httpOnly: true,
+ sameSite: 'lax',
+ path: '/',
+ // When working on localhost, the cookie domain must be omitted entirely (https://stackoverflow.com/a/1188145)
+ domain: `.${LEARNHOUSE_TOP_DOMAIN}`,
+ secure: !isDevEnv,
+ },
+ },
+ },
callbacks: {
async jwt({ token, user, account }: any) {
// First sign in with Credentials provider
diff --git a/apps/web/app/orgs/[orgslug]/login/login.tsx b/apps/web/app/login/login.tsx
similarity index 94%
rename from apps/web/app/orgs/[orgslug]/login/login.tsx
rename to apps/web/app/login/login.tsx
index ec533a31..fec973fc 100644
--- a/apps/web/app/orgs/[orgslug]/login/login.tsx
+++ b/apps/web/app/login/login.tsx
@@ -57,16 +57,16 @@ const LoginClient = (props: LoginClientProps) => {
redirect: false,
email: values.email,
password: values.password,
- callbackUrl: '/'
+ callbackUrl: '/redirect_from_auth'
});
if (res && res.error) {
setError("Wrong Email or password");
setIsSubmitting(false);
- }else {
+ } else {
await signIn('credentials', {
email: values.email,
password: values.password,
- callbackUrl: '/'
+ callbackUrl: '/redirect_from_auth'
});
}
},
@@ -177,7 +177,7 @@ const LoginClient = (props: LoginClientProps) => {
-